Register a Cordis Service in DeepSeek Harness
To expose a Cordis service in DeepSeek Harness, mount a Service subclass that registers a name on its context, declare the TypeScript context type, and have consumers declare the service in inject. Registration, typing and dependency readiness are separate responsibilities.
DeepSeek Harness: what is a service, and who owns it?
The Cordis primer describes a context as a repository of named services. Plugins consume capabilities through keys such as ctx.tools and ctx.llm rather than importing a concrete provider. The Service API says that a Service subclass loaded as a plugin registers under ctx.<name>. Its constructor calls super(ctx, name); the registration is removed with the owning fiber.
Three pieces need to agree. The runtime registration supplies an instance under a name. TypeScript declaration merging makes that property known to the compiler. A consumer's inject declares that the service must be available before its plugin runs. A type declaration alone does not create an instance, and an installed provider does not mean every scope sees it.
| Piece | Purpose | Not a substitute for |
|---|---|---|
Service subclass | Provide a named runtime API | Mounting the provider |
Context declaration merge | Type the named property | Runtime registration |
inject | Express a required service | Installing or mounting a provider |
| Plugin composition | Mount provider and consumer | Verifying their behavior |
DeepSeek Harness: how do I register a provider?
The service tutorial demonstrates a greeter service. This condensed example keeps the tutorial's registration and typing pattern, without requiring a model call:
import { Service, type Context } from '@deepseek-ai/cordis'
declare module '@deepseek-ai/cordis' {
interface Context {
greeter: GreeterService
}
}
export class GreeterService extends Service {
constructor(ctx: Context) {
super(ctx, 'greeter')
}
greet(who: string) {
return `Hello, ${who}!`
}
}
export const name = 'greeter'
export function apply(ctx: Context) {
ctx.plugin(GreeterService)
}
Here super(ctx, 'greeter') registers the instance under the runtime key. The declare module block extends the Context interface so TypeScript can type ctx.greeter. The exported apply mounts the service class as a child plugin. These are related but distinct operations: removing the type augmentation does not unregister a running service, while adding the augmentation alone does not mount the provider.
The tutorial also shows a class plugin as a provider. Choose the form appropriate to the loader and composition you actually use; avoid treating this small greeting service as a built-in Harness capability. Its purpose is to demonstrate the contract, not to promise storage, networking, or authentication.
DeepSeek Harness: how does another plugin consume it?
The same tutorial declares a dependency and accesses the service from the consumer's context:
import type { Context } from '@deepseek-ai/cordis'
export const inject = ['greeter']
export function apply(ctx: Context) {
console.log(ctx.greeter.greet('world'))
}
The consumer needs the provider's context type declaration available to its TypeScript compilation. At runtime, Cordis waits for the declared required service before activating the consumer. The services and dependencies guide distinguishes an optional lookup: omit the required injection and use ctx.get() when the consumer can genuinely operate without that capability. A required dependency and an optional lookup communicate different behavior when the service is absent.
Do not use configuration-list order as a replacement for a dependency. The tutorial says entries can start concurrently. inject expresses readiness; it does not install the provider, prove the service's implementation is correct, or make an unrelated scoped instance visible to this consumer. When a required service disappears, the guide says dependent plugins dispose and load again when it returns. Consumers must be designed for that lifecycle rather than retaining stale assumptions indefinitely.
DeepSeek Harness: how do I put the pieces together?
- Define the service contract and choose a context key. Check existing keys and the expected scope before introducing a provider.
- Implement a
Servicesubclass and callsuper(ctx, name). Mount it as a plugin using the composition mechanism for your environment. - Add the matching
Contexttype augmentation where consumers can compile against it. Ensure the type and runtime key agree. - Declare the service in the consumer's
injectwhen it is required, then call the documented service method fromapply. Use optional lookup only when absence is handled deliberately. - Mount both provider and consumer in the intended composition. Exercise the service, then test unload and reactivation when the dependency disappears and returns.
The official tutorial uses a standalone Cordis tutorial composition, whereas a Harness profile may use a different assembly and overlays. Follow the installation and composition instructions for that environment rather than assuming a tutorial path is a universal profile path. A configured module name, the actual provider's activation, and a working method call are separate observations.
DeepSeek Harness: why might the consumer remain pending?
First check that the provider was mounted and started successfully. A type-checking success only establishes that TypeScript knows the property; it does not show that Cordis registered a runtime instance. Next compare the name in super, the Context declaration and the consumer's inject. A spelling mismatch can turn three individually plausible pieces into different keys.
Then inspect the context scope. The services guide documents isolation for separate plugin groups: the same service name can resolve to different instances within different groups. Check which context mounts the provider and which context activates the consumer. A provider visible in one isolated group is not evidence that it is available in another. See pending plugins and missing services for startup diagnosis.
Finally inspect the provider's original startup error before changing the consumer. A waiting consumer can be a downstream symptom. If the service is optional, handle its absence at the lookup site; if it is required, silently ignoring absence changes the intended contract. Test the actual method behavior after activation, not merely the presence of the key.
DeepSeek Harness: what are the limits and safety boundaries?
Registering a service is not a security review. A provider can execute code and expose behavior to consumers; inspect its source, configuration and dependencies before using it in a sensitive environment. A matching type, successful injection or completed startup does not guarantee safe behavior. Scope isolation controls service resolution as documented; it is not described here as an operating-system sandbox.
Lifecycle matters as much as startup. The base service registration is tied to its owning fiber, and the primer describes registrations as reversible effects. If a plugin owns external resources, use the appropriate documented lifecycle and cleanup mechanism; the greeting example does not open such resources. The exact interfaces and availability depend on the installed version and composition, so verify those contracts before applying an example to an existing deployment.
DeepSeek Harness: what do the terms mean?
- Service: a named capability exposed through a Cordis context.
- Provider: the plugin that supplies the service implementation.
- Consumer: a plugin that uses the capability.
- Injection: a declaration of services required for plugin activation.
- Declaration merging: TypeScript's way to extend the
Contextinterface with the service type. - Fiber: the owning plugin lifecycle to which service registration is attached.
Frequently asked questions
Does a Context type declaration register a service?
No. The provider must be mounted and register the service at runtime.
Why declare inject?
It declares a required service so Cordis waits for that dependency before activating the plugin.
Are isolated service scopes operating-system sandboxes?
No such guarantee follows from the documented service-resolution isolation.
Sources
Every claim in this article was checked against the sources below. Community discussions are user reports, not official behavior.
This is an independent community article, not official DeepSeek documentation. Listing a plugin in the registry is not a security review.