mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`, `verify-translation-pairing --write` for the touched bilingual pairs, `gen-doc-graphs`, and one typert snapshot whose ids embed character offsets. `pnpm run rescope-vendor --check` verifies the result. Renames nine vendored packages (cordis, cosmokit, schemastery and the six @cordisjs plugins) and every reference that resolves them: manifest names and dependency keys, module specifiers including declare-module merges, cordis.yml plugin names, tsconfig paths, every Markdown fence, and `docs/` prose. Directory names, upstream versions, and dependency ranges are unchanged, so vendor/README.md still reads as an upstream snapshot; its manifest table gains an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed at each fork's origin. The tutorial tier follows the rename end to end: its yaml fences named plugins the Loader can no longer resolve, its `ts ignore-check` fences disagreed with the compiled fences beside them, and its prose quoted both. The contracts that told readers to keep upstream names — the root convention and the vendoring cookbook's tree comment and manifest invariant — now say to rescope instead. Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle purity gate now names the vendored libraries a browser bundle inlines, and the files where a bare `cordis` is an agent-preset id keep that product data.
116 lines
4.2 KiB
TypeScript
116 lines
4.2 KiB
TypeScript
import { defineProperty } from '@deepseek-ai/cosmokit'
|
|
import { Context } from './context.ts'
|
|
import { createCallable, joinPrototype, symbols, type Tracker } from './utils.ts'
|
|
|
|
/**
|
|
* Base class for services that expose a named API on `ctx`.
|
|
*
|
|
* Subclasses call `super(ctx, name)` from their constructor. The service is
|
|
* registered immediately and is automatically removed with the owning fiber.
|
|
*/
|
|
export abstract class Service<out T = never> {
|
|
/** Symbol key of an instance method run after construction (class plugins). */
|
|
static readonly init: unique symbol = symbols.init
|
|
/** Symbol key of the availability predicate passed to `ctx.provide()`. */
|
|
static readonly check: unique symbol = symbols.check
|
|
/** Symbol key of the phantom intercept-config type parameter. */
|
|
static readonly config: unique symbol = symbols.config
|
|
/** Symbol key of the call body making a service callable (e.g. `ctx.logger()`). */
|
|
static readonly invoke: unique symbol = symbols.invoke
|
|
/** Symbol key of the helper deriving an extended service instance. */
|
|
static readonly extend: unique symbol = symbols.extend
|
|
/** Symbol key of the tracker metadata used for context tracing. */
|
|
static readonly tracker: unique symbol = symbols.tracker
|
|
/** Symbol key of the intercept-config resolution helper below. */
|
|
static readonly resolveConfig: unique symbol = symbols.resolveConfig
|
|
|
|
declare [symbols.config]: T
|
|
|
|
/** The service name this instance is registered under. */
|
|
public name!: string
|
|
|
|
/**
|
|
* Register this instance as `name` in the current context.
|
|
*
|
|
* Calls `ctx.reflect.provide(name, this, this[Service.check])`, so the
|
|
* service is unregistered automatically when the owning fiber unloads.
|
|
* Services with a `[Service.invoke]` body return a callable instance.
|
|
*
|
|
* @param ctx — the context to register in (stored as `this.ctx`).
|
|
* @param name — the service name; defaults to the static `provide` field.
|
|
*/
|
|
constructor(protected ctx: Context, name: string) {
|
|
name ??= this.constructor['provide'] as string
|
|
|
|
let self = this
|
|
const tracker: Tracker = {
|
|
associate: name,
|
|
property: 'ctx',
|
|
}
|
|
if (self[symbols.invoke]) {
|
|
self = createCallable(name, joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker)
|
|
}
|
|
self.ctx = ctx
|
|
self.name = name
|
|
defineProperty(self, symbols.tracker, tracker)
|
|
|
|
self.ctx.reflect.provide(name, self, this[symbols.check])
|
|
return self
|
|
}
|
|
|
|
protected [symbols.filter](ctx: Context) {
|
|
return ctx[symbols.isolate][this.name] === this.ctx[symbols.isolate][this.name]
|
|
}
|
|
|
|
protected [symbols.extend](props?: any) {
|
|
let self: any
|
|
if (this[Service.invoke]) {
|
|
self = createCallable(this.name, this, this[symbols.tracker])
|
|
} else {
|
|
self = Object.create(this)
|
|
}
|
|
return Object.assign(self, props)
|
|
}
|
|
|
|
/**
|
|
* Merge intercept config from ancestors with optional base and head values.
|
|
*
|
|
* Entries added closer to the root apply first; `base` is prepended and
|
|
* `head` appended. Uses `Config.merge` when the service declares one,
|
|
* otherwise a shallow `Object.assign`.
|
|
*
|
|
* @param base — lowest-precedence config merged before all intercepts.
|
|
* @param head — highest-precedence config merged after all intercepts.
|
|
* @returns the merged config.
|
|
*/
|
|
[symbols.resolveConfig](base?: T, head?: T): T {
|
|
let intercept = this.ctx[Context.intercept]
|
|
const configs: any[] = []
|
|
while (this.name in intercept) {
|
|
if (Object.hasOwn(intercept, this.name)) {
|
|
configs.unshift(intercept[this.name])
|
|
}
|
|
intercept = Object.getPrototypeOf(intercept)
|
|
}
|
|
if (base) configs.unshift(base)
|
|
if (head) configs.push(head)
|
|
if (this['Config']?.merge) {
|
|
return this['Config'].merge(...configs)
|
|
} else {
|
|
return Object.assign({}, ...configs)
|
|
}
|
|
}
|
|
|
|
static [Symbol.hasInstance](instance: any) {
|
|
if (!instance) return false
|
|
let constructor = instance.constructor
|
|
while (constructor) {
|
|
// constructor may be a proxy
|
|
constructor = constructor.prototype?.constructor
|
|
if (constructor === this) return true
|
|
constructor &&= Object.getPrototypeOf(constructor)
|
|
}
|
|
return false
|
|
}
|
|
}
|