Files
deepseek-harness/website/zh-CN/api/cordis/fiber.md
T

283 lines
8.5 KiB
Markdown
Raw Normal View History

<!-- Generated by scripts/gen-website-api.ts — do not edit by hand. Run `pnpm run gen-website-api` to regenerate. -->
2026-07-09 16:07:58 +08:00
# Fiber
A fiber is one loaded plugin instance: its lifecycle state, validated config, and registered effects. `ctx.fiber` is the current fiber; `ctx.effect()` delegates to it.
2026-07-09 16:07:58 +08:00
### ctx.effect(execute, label?)
```ts website-api
effect(execute: () => SyncEffect, label?: string): Disposable<Promise<void>>
effect(execute: () => Effect, label?: string): AsyncDisposable<Promise<void>>
```
Register a cleanup-aware effect on this fiber.
`execute` runs immediately; the disposers it produces are collected and run (in reverse order) either when the returned disposer is called or when the fiber unloads, whichever comes first. Calling the disposer twice is a no-op. Throws `CordisError('INACTIVE_EFFECT')` if the fiber is already disposed, and `TypeError` if `execute` returns an invalid shape.
- `execute` — the effect body; see `Effect` for accepted shapes.
- `label` — effect label shown in `getEffects()` diagnostics.
**Returns** a disposer that tears the effect down and settles once done.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L363)
### ctx.fiber
2026-07-09 16:07:58 +08:00
```ts website-api
fiber: Fiber
2026-07-09 16:07:58 +08:00
```
The fiber (plugin runtime instance) that owns this context.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L11)
2026-07-09 16:07:58 +08:00
## The Fiber class
Runtime instance of one plugin application.
A fiber tracks dependency state, validated config, lifecycle effects, and cleanup for the plugin context returned by `ctx.plugin()`.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L154)
2026-07-09 16:07:58 +08:00
### fiber.uid
```ts website-api
public uid: number | null
```
Unique id within the registry; 0 for the root fiber, `null` once disposed.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L156)
2026-07-09 16:07:58 +08:00
### fiber.ctx
2026-07-09 16:07:58 +08:00
```ts website-api
public readonly ctx: Context
```
2026-07-09 16:07:58 +08:00
The context this fiber's plugin runs in (extends the parent context).
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L158)
2026-07-09 16:07:58 +08:00
### fiber.config
```ts website-api
public config: any
```
The validated plugin config (updated by `update()`).
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L160)
### fiber.state
```ts website-api
public state
```
Current lifecycle state; transitions emit `internal/status`.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L162)
### fiber.dispose
```ts website-api
public readonly dispose: () => Promise<void>
```
Dispose this fiber: unload the plugin, then settle once cleanup finished.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L164)
### fiber.store
```ts website-api
public store: Dict<Impl> | undefined
```
Snapshot of required service implementations while loaded; `undefined` otherwise.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L166)
2026-07-09 16:07:58 +08:00
### fiber.inertia
2026-07-09 16:07:58 +08:00
```ts website-api
public inertia: Promise<void> | undefined
```
2026-07-09 16:07:58 +08:00
The in-flight load/unload transition, if one is currently running.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L168)
2026-07-09 16:07:58 +08:00
### fiber.name
```ts website-api
get name()
```
2026-07-09 16:07:58 +08:00
The plugin's display name, inherited from the nearest named ancestor, else `'root'`.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L284)
2026-07-09 16:07:58 +08:00
### fiber.assertActive()
2026-07-09 16:07:58 +08:00
```ts website-api
assertActive()
2026-07-09 16:07:58 +08:00
```
Throw if the fiber has already been disposed.
2026-07-09 16:07:58 +08:00
**Returns** nothing when the fiber is still active.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L299)
2026-07-09 16:07:58 +08:00
### fiber.effect(execute, label?)
2026-07-09 16:07:58 +08:00
```ts website-api
effect(execute: () => SyncEffect, label?: string): Disposable<Promise<void>>
effect(execute: () => Effect, label?: string): AsyncDisposable<Promise<void>>
2026-07-09 16:07:58 +08:00
```
Register a cleanup-aware effect on this fiber.
`execute` runs immediately; the disposers it produces are collected and run (in reverse order) either when the returned disposer is called or when the fiber unloads, whichever comes first. Calling the disposer twice is a no-op. Throws `CordisError('INACTIVE_EFFECT')` if the fiber is already disposed, and `TypeError` if `execute` returns an invalid shape.
2026-07-09 16:07:58 +08:00
- `execute` — the effect body; see `Effect` for accepted shapes.
- `label` — effect label shown in `getEffects()` diagnostics.
2026-07-09 16:07:58 +08:00
**Returns** a disposer that tears the effect down and settles once done.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L363)
### fiber.getEffects()
```ts website-api
getEffects()
```
Return metadata for currently registered effects.
**Returns** one `EffectMeta` tree per labeled live effect.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L436)
### fiber.await()
```ts website-api
async await()
```
Wait for current lifecycle work and rethrow startup errors.
**Returns** this fiber, once it has settled into a stable state.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L560)
2026-07-09 16:07:58 +08:00
### fiber.restart()
```ts website-api
async restart()
```
2026-07-09 16:07:58 +08:00
Dispose and immediately reload this plugin with its current config.
2026-07-09 16:07:58 +08:00
**Returns** a promise resolving once the reload settled.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L574)
2026-07-09 16:07:58 +08:00
### fiber.update(config, noSave?)
2026-07-09 16:07:58 +08:00
```ts website-api
update(config: any, noSave = false)
2026-07-09 16:07:58 +08:00
```
Validate and apply new config, then restart the plugin.
Runs the `internal/update` waterfall first, so update hooks (and HMR) can veto or replace the restart.
- `config` — the new raw config; validated before anything restarts.
- `noSave` — hint for persistence hooks not to write the change back.
**Returns** nothing; the restart runs behind the `internal/update` waterfall.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L592)
## Effect
Effect body result accepted by `ctx.effect()` and plugin startup.
Either a single disposer, a promise of one, or a (possibly async) iterable yielding several — generator effects register each yielded disposer as it is produced.
```ts website-api
type Effect<T = any> =
| SyncEffect<T>
| AsyncEffect<T>
```
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L82)
## Disposable
Function returned by an effect to release resources during disposal.
Disposers run in reverse registration order when the owning fiber unloads; they may be async, in which case unloading awaits them.
```ts website-api
type Disposable<T = any> = () => T
```
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L73)
## EffectMeta
2026-07-09 16:07:58 +08:00
Tree node used to expose nested effect labels for diagnostics.
```ts website-api
interface EffectMeta {
/** Human-readable effect label, e.g. `ctx.on("event")` or `ctx.provide("name")`. */
label: string
/** Metadata of nested effects registered while this effect ran. */
children: EffectMeta[]
}
```
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L95)
## CordisError
Framework error with a stable machine-readable code.
```ts website-api
class CordisError extends Error {
/**
* @param code — the stable error code; also the default message.
* @param message — optional human-readable override.
*/
constructor(public code: CordisError.Code, message?: string)
}
namespace CordisError {
export type Code = keyof typeof Code
export const Code = {
INACTIVE_EFFECT: 'cannot create effect on inactive context',
} as const
2026-07-09 16:07:58 +08:00
}
```
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L127)
## ValidationError
Error raised when plugin configuration fails standard-schema validation.
```ts website-api
class ValidationError extends TypeError {
name = 'ValidationError'
/**
* Build the aggregated message from schema issues.
*
* @param issues — the standard-schema issues, one message line each.
*/
constructor(issues: readonly StandardSchemaV1.Issue[])
}
```
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/fiber.ts#L18)