@cef-ai/agent-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -0
- package/dist/config/define-agent.d.ts +181 -0
- package/dist/config/define-agent.d.ts.map +1 -0
- package/dist/config/define-agent.js +35 -0
- package/dist/config/define-agent.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/decorators.d.ts +38 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +60 -0
- package/dist/decorators.js.map +1 -0
- package/dist/engagement.d.ts +13 -0
- package/dist/engagement.d.ts.map +1 -0
- package/dist/engagement.js +40 -0
- package/dist/engagement.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/symbols.d.ts +33 -0
- package/dist/symbols.d.ts.map +1 -0
- package/dist/symbols.js +12 -0
- package/dist/symbols.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @cef-ai/agent-sdk
|
|
2
|
+
|
|
3
|
+
Author agents for the Cere Execution Fabric: a small surface of decorators
|
|
4
|
+
and types that maps directly to the runtime contract.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @cef-ai/agent-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
For tests, also install the harness:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add -D @cef-ai/testing
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
19
|
+
|
|
20
|
+
An agent is a default-exported class with decorated methods. `@OnEvent`
|
|
21
|
+
binds an event type to a handler; `@OnStart` and `@OnClose` are lifecycle
|
|
22
|
+
hooks. `Context` is the single object the runtime threads through every
|
|
23
|
+
call.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {
|
|
27
|
+
OnClose,
|
|
28
|
+
OnEvent,
|
|
29
|
+
OnStart,
|
|
30
|
+
type Context,
|
|
31
|
+
type Event,
|
|
32
|
+
type OnCloseReason,
|
|
33
|
+
} from "@cef-ai/agent-sdk";
|
|
34
|
+
|
|
35
|
+
interface UserMessage {
|
|
36
|
+
text: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default class Echo {
|
|
40
|
+
@OnStart
|
|
41
|
+
async onStart(ctx: Context) {
|
|
42
|
+
ctx.log.info("started");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@OnEvent("user_message")
|
|
46
|
+
async onMessage(event: Event<UserMessage>, ctx: Context) {
|
|
47
|
+
await ctx
|
|
48
|
+
.cubby("history")
|
|
49
|
+
.exec("INSERT INTO messages(text, ts) VALUES (?, ?)", [
|
|
50
|
+
event.payload.text,
|
|
51
|
+
event.ts,
|
|
52
|
+
]);
|
|
53
|
+
await ctx.publish("ack", { for: event.id });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@OnClose
|
|
57
|
+
async onClose(ctx: Context, reason: OnCloseReason) {
|
|
58
|
+
ctx.log.info("closing", { reason });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Pair the class with a `cef.config.ts`:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { defineAgent } from "@cef-ai/agent-sdk/config";
|
|
67
|
+
|
|
68
|
+
export default defineAgent({
|
|
69
|
+
id: "echo",
|
|
70
|
+
version: "1.0.0",
|
|
71
|
+
entry: "./agent.ts",
|
|
72
|
+
cubbies: [{ alias: "history", migrations: "./migrations/history" }],
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## API summary
|
|
77
|
+
|
|
78
|
+
| Kind | Symbol | Notes |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| Decorator | `@OnEvent(type)` | Bind an event type (string literal) to a handler. |
|
|
81
|
+
| Decorator | `@OnStart` | Mark the start lifecycle hook. |
|
|
82
|
+
| Decorator | `@OnClose` | Mark the close lifecycle hook. |
|
|
83
|
+
| Type | `Context` | Per-instance ctx — `cubby`, `models`, `fetch`, `publish`, `settings`, `close`, `log`. |
|
|
84
|
+
| Type | `Event<P>` | `{ id, type, ts, from, payload: P }`. |
|
|
85
|
+
| Type | `CubbyHandle` | `query(sql, params)` / `exec(sql, params)` over per-alias storage. |
|
|
86
|
+
| Type | `ModelHandle<I,O>` | `infer(input)` / `stream(input)` per declared model alias. |
|
|
87
|
+
| Type | `Logger` | Leveled structured log: `info` / `warn` / `error` / `debug`. |
|
|
88
|
+
| Type | `OnCloseReason` | `"revoked" \| "idle_timeout" \| "closed_by_agent" \| "failed"`. |
|
|
89
|
+
| Type | `FetchInit` | Subset of `RequestInit` accepted by `ctx.fetch`. |
|
|
90
|
+
| Interface | `KnownEventTypes` | Declaration-merged event-type map populated by typegen. |
|
|
91
|
+
| Function | `defineAgent(config)` | Identity helper that preserves literal types of `AgentConfig`. |
|
|
92
|
+
| Type | `AgentConfig` | Top-level config: `id`, `version`, `entry`, `cubbies`, `models`, `settings`, `fetch`, `publishes`, `lifecycle`. |
|
|
93
|
+
|
|
94
|
+
## Subpath exports
|
|
95
|
+
|
|
96
|
+
| Specifier | Purpose |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `@cef-ai/agent-sdk` | Decorators, `Context`, `Event`, `KnownEventTypes`, `Logger`, `ModelHandle`, `CubbyHandle`, `FetchInit`, `OnCloseReason`. |
|
|
99
|
+
| `@cef-ai/agent-sdk/config` | `defineAgent` and the `AgentConfig` shape — used in `cef.config.ts`. |
|
|
100
|
+
|
|
101
|
+
For testing, use `@cef-ai/testing` directly — `import { testAgent } from "@cef-ai/testing"`.
|
|
102
|
+
|
|
103
|
+
## Companion packages
|
|
104
|
+
|
|
105
|
+
- [`@cef-ai/cli`](../cli) — `cef build` (esbuild + manifest), `cef typegen`
|
|
106
|
+
(populates `KnownEventTypes`), `cef inspect`.
|
|
107
|
+
- [`@cef-ai/testing`](../testing) — simulator harness for unit and
|
|
108
|
+
integration tests.
|
|
109
|
+
- [`@cef-ai/eslint-plugin`](../eslint-plugin) — editor-time lints mirroring
|
|
110
|
+
the build-time checks.
|
|
111
|
+
|
|
112
|
+
## References
|
|
113
|
+
|
|
114
|
+
- Agent SDK spec: `../../../company-memory-bank/specs/platform/03-components/agent-sdk.md`
|
|
115
|
+
- Runtime integration contract: `../../../company-memory-bank/specs/platform/03-components/sdk-runtime-integration-contract.md`
|
|
116
|
+
- Implementation plan: `../../../company-memory-bank/plans/2026-04-27-sdk-implementation-plan.md`
|
|
117
|
+
|
|
118
|
+
The `../company-memory-bank/...` paths are local references to an internal
|
|
119
|
+
sibling repo and are not browsable from a fresh clone.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative configuration for an agent bundle.
|
|
3
|
+
*
|
|
4
|
+
* The shape mirrors `AgentManifest` in the platform spec
|
|
5
|
+
* (`specs/platform/prototype.md` §"Marketplace API → POST
|
|
6
|
+
* /api/v1/marketplace/agents"). `cef build` consumes this config to derive
|
|
7
|
+
* the manifest body that is later signed and published; identity fields
|
|
8
|
+
* (`agentId`, `agentServicePubkey`, `signature`) are filled in by
|
|
9
|
+
* `cef publish` and are NOT authored here.
|
|
10
|
+
*
|
|
11
|
+
* Per ADR-019, an agent contains one or more **engagements** — goal-bound
|
|
12
|
+
* code units. The config exposes two equivalent shapes for declaring them:
|
|
13
|
+
*
|
|
14
|
+
* - `entry: "./src/agent.ts"` — single-engagement shorthand. Equivalent to
|
|
15
|
+
* `engagements: [{ id: "default", entry: "./src/agent.ts" }]`.
|
|
16
|
+
* - `engagements: [{ id, entry }, ...]` — explicit multi-engagement form.
|
|
17
|
+
*
|
|
18
|
+
* Exactly one of `entry` or `engagements` must be provided; the build step
|
|
19
|
+
* enforces this.
|
|
20
|
+
*/
|
|
21
|
+
/** JSON Schema document; left intentionally loose (consumed verbatim). */
|
|
22
|
+
export type JSONSchema = Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* One row of `targeting.engagements[]` — same shape as the platform's
|
|
25
|
+
* legacy `Deployment.Engagements[]` selection table. The build step
|
|
26
|
+
* validates that every `id` references a declared engagement and every
|
|
27
|
+
* rule `name` is one of the supported names.
|
|
28
|
+
*/
|
|
29
|
+
export interface TargetingEngagement {
|
|
30
|
+
/** Engagement id; must match a declared engagement. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Selection rules — see {@link Rule}. Empty array → defaults applied. */
|
|
33
|
+
rules?: Rule[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A single selection rule on a targeting engagement. The supported
|
|
37
|
+
* vocabulary in v1 is:
|
|
38
|
+
*
|
|
39
|
+
* - `priority` (int, default 0) — lower value = higher priority.
|
|
40
|
+
* - `weight` (int, default 100) — probabilistic split within a tier.
|
|
41
|
+
* - `limit` (int) — daily UTC cap, per-vault. Counter-backed by the
|
|
42
|
+
* platform; treated as advisory by the in-memory simulator.
|
|
43
|
+
*
|
|
44
|
+
* Future names are additive; the build validator rejects unknown names so
|
|
45
|
+
* authors get an early error instead of silently misrouted traffic.
|
|
46
|
+
*/
|
|
47
|
+
export interface Rule {
|
|
48
|
+
name: "priority" | "weight" | "limit";
|
|
49
|
+
value: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Engagement-selection decision table emitted into the manifest. Same shape
|
|
53
|
+
* as legacy `Deployment.Engagements[]` (without Stream binding / Triggers);
|
|
54
|
+
* the platform's existing evaluator consumes it directly. Engagements
|
|
55
|
+
* declared on the agent but **not** listed here are not selectable for new
|
|
56
|
+
* Jobs (per the prototype spec).
|
|
57
|
+
*/
|
|
58
|
+
export interface Targeting {
|
|
59
|
+
engagements: TargetingEngagement[];
|
|
60
|
+
}
|
|
61
|
+
/** Marketplace presentation card. */
|
|
62
|
+
export interface AgentCard {
|
|
63
|
+
name: string;
|
|
64
|
+
description: string;
|
|
65
|
+
iconUrl?: string;
|
|
66
|
+
/** Free-form tags used by marketplace browse. */
|
|
67
|
+
capabilities?: string[];
|
|
68
|
+
}
|
|
69
|
+
/** One row of `settings[]` — declared at the agent level. */
|
|
70
|
+
export interface SettingDecl {
|
|
71
|
+
key: string;
|
|
72
|
+
type: "string" | "number" | "boolean" | "url" | "secret";
|
|
73
|
+
required?: boolean;
|
|
74
|
+
label?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
default?: unknown;
|
|
77
|
+
}
|
|
78
|
+
/** One row of `cubbies[]`. */
|
|
79
|
+
export interface CubbyDecl {
|
|
80
|
+
alias: string;
|
|
81
|
+
/** Path (relative to `cef.config.ts`) of a directory of `*.sql` migrations. */
|
|
82
|
+
migrations?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface AgentConfig {
|
|
85
|
+
/**
|
|
86
|
+
* Human-friendly identifier used as the marketplace `alias`. The signed
|
|
87
|
+
* manifest's full `agentId` is `"{agentServicePubkey}:{uuid}"`, assigned
|
|
88
|
+
* by `cef publish` — `id` here is the alias, not the composite id.
|
|
89
|
+
*/
|
|
90
|
+
id: string;
|
|
91
|
+
version: string;
|
|
92
|
+
/**
|
|
93
|
+
* Optional — overrides the alias derived from {@link AgentConfig.id}
|
|
94
|
+
* when the user wants the marketplace alias to differ from the build
|
|
95
|
+
* identifier (rare). Carried verbatim into `manifest.alias`.
|
|
96
|
+
*/
|
|
97
|
+
alias?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Optional free-form pointer to where the source lives — git URL, tarball,
|
|
100
|
+
* CID. Carried verbatim into `manifest.source`.
|
|
101
|
+
*/
|
|
102
|
+
source?: string;
|
|
103
|
+
/** Marketplace presentation card. Optional with empty defaults. */
|
|
104
|
+
card?: AgentCard;
|
|
105
|
+
/**
|
|
106
|
+
* Vault scopes the agent needs at AgentConnection time. Defaults to
|
|
107
|
+
* `["default"]` when omitted.
|
|
108
|
+
*/
|
|
109
|
+
requiredScopes?: string[];
|
|
110
|
+
/**
|
|
111
|
+
* Per-Job idle timeout as a **duration string** — `"15m"`, `"30s"`,
|
|
112
|
+
* `"1h"`, `"500ms"`, `"2d"`. After this much time has passed without
|
|
113
|
+
* a new activity on a Job, the orchestrator marks the Job terminal
|
|
114
|
+
* with `terminalReason: "idle_timeout"` and dispatches the synthetic
|
|
115
|
+
* `__close__` event (per the
|
|
116
|
+
* [orchestrator jobs redesign](../../specs/platform/orchestrator-jobs-redesign.md)).
|
|
117
|
+
*
|
|
118
|
+
* The build step parses this into milliseconds and writes the integer
|
|
119
|
+
* value into `manifest.idleTimeout`. Defaults to `"30m"` when omitted.
|
|
120
|
+
* Set to `"0s"` to disable idle-based termination — the Job will only
|
|
121
|
+
* terminate on `ctx.close(reason)` or AgentConnection revocation.
|
|
122
|
+
*
|
|
123
|
+
* Accepted units: `ms`, `s`, `m`, `h`, `d`. Whitespace between the
|
|
124
|
+
* number and the unit is ignored.
|
|
125
|
+
*/
|
|
126
|
+
idleTimeout?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Single-engagement shorthand. Equivalent to
|
|
129
|
+
* `engagements: [{ id: "default", entry }]`. Mutually exclusive with
|
|
130
|
+
* {@link AgentConfig.engagements}.
|
|
131
|
+
*/
|
|
132
|
+
entry?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Multi-engagement declaration (target shape per ADR-019). Each entry
|
|
135
|
+
* has its own stable `id` (matching `[a-zA-Z][a-zA-Z0-9_-]*`) and a path
|
|
136
|
+
* to a TypeScript source file exporting an engagement class as default.
|
|
137
|
+
* Mutually exclusive with {@link AgentConfig.entry}.
|
|
138
|
+
*/
|
|
139
|
+
engagements?: Array<{
|
|
140
|
+
id: string;
|
|
141
|
+
entry: string;
|
|
142
|
+
}>;
|
|
143
|
+
/** Reserved for nested multi-bundle configs (Pattern 1). */
|
|
144
|
+
agents?: AgentConfig[];
|
|
145
|
+
models?: Record<string, string>;
|
|
146
|
+
uses?: Record<string, string>;
|
|
147
|
+
cubbies?: CubbyDecl[];
|
|
148
|
+
settings?: SettingDecl[];
|
|
149
|
+
fetch?: {
|
|
150
|
+
allow?: string[];
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Schemas for events this agent **owns** — events it publishes, plus
|
|
154
|
+
* events it handles whose publisher is not a declared peer. Per
|
|
155
|
+
* `prototype.md`, peer-published event schemas live in the peer's
|
|
156
|
+
* manifest and are pulled in by `cef typegen`.
|
|
157
|
+
*/
|
|
158
|
+
eventSchemas?: Record<string, JSONSchema>;
|
|
159
|
+
/**
|
|
160
|
+
* Optional engagement-selection decision table (ADR-019). Pinned to a
|
|
161
|
+
* Job at creation time; subsequent events for that Job run through the
|
|
162
|
+
* pinned engagement. When omitted, the build defaults to a single
|
|
163
|
+
* targeting entry referencing the first declared engagement.
|
|
164
|
+
*/
|
|
165
|
+
targeting?: Targeting;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Identity function with type narrowing — used at the top of a bundle's
|
|
169
|
+
* `cef.config.ts` to declare an `AgentConfig` while preserving the literal
|
|
170
|
+
* types of its fields for better downstream inference.
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* export default defineAgent({
|
|
174
|
+
* id: "echo",
|
|
175
|
+
* version: "1.0.0",
|
|
176
|
+
* entry: "./src/agent.ts",
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare const defineAgent: <T extends AgentConfig>(c: T) => T;
|
|
181
|
+
//# sourceMappingURL=define-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-agent.d.ts","sourceRoot":"","sources":["../../src/config/define-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;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EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,WAAW,EAAE,GAAG,CAAC,KAAG,CAAM,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative configuration for an agent bundle.
|
|
3
|
+
*
|
|
4
|
+
* The shape mirrors `AgentManifest` in the platform spec
|
|
5
|
+
* (`specs/platform/prototype.md` §"Marketplace API → POST
|
|
6
|
+
* /api/v1/marketplace/agents"). `cef build` consumes this config to derive
|
|
7
|
+
* the manifest body that is later signed and published; identity fields
|
|
8
|
+
* (`agentId`, `agentServicePubkey`, `signature`) are filled in by
|
|
9
|
+
* `cef publish` and are NOT authored here.
|
|
10
|
+
*
|
|
11
|
+
* Per ADR-019, an agent contains one or more **engagements** — goal-bound
|
|
12
|
+
* code units. The config exposes two equivalent shapes for declaring them:
|
|
13
|
+
*
|
|
14
|
+
* - `entry: "./src/agent.ts"` — single-engagement shorthand. Equivalent to
|
|
15
|
+
* `engagements: [{ id: "default", entry: "./src/agent.ts" }]`.
|
|
16
|
+
* - `engagements: [{ id, entry }, ...]` — explicit multi-engagement form.
|
|
17
|
+
*
|
|
18
|
+
* Exactly one of `entry` or `engagements` must be provided; the build step
|
|
19
|
+
* enforces this.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Identity function with type narrowing — used at the top of a bundle's
|
|
23
|
+
* `cef.config.ts` to declare an `AgentConfig` while preserving the literal
|
|
24
|
+
* types of its fields for better downstream inference.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* export default defineAgent({
|
|
28
|
+
* id: "echo",
|
|
29
|
+
* version: "1.0.0",
|
|
30
|
+
* entry: "./src/agent.ts",
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const defineAgent = (c) => c;
|
|
35
|
+
//# sourceMappingURL=define-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-agent.js","sourceRoot":"","sources":["../../src/config/define-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAuJH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAwB,CAAI,EAAK,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,IAAI,EACJ,WAAW,EACX,SAAS,EACT,mBAAmB,GACpB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { KnownEventTypes } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mark an instance method as the handler for an inbound event of type `T`.
|
|
4
|
+
*
|
|
5
|
+
* The first overload uses {@link KnownEventTypes} (declaration-merged by
|
|
6
|
+
* the typegen step in agent-sdk consumers) so authors get autocompletion
|
|
7
|
+
* for the event types declared in their agent manifest. The second
|
|
8
|
+
* overload accepts any string for ergonomic use without typegen.
|
|
9
|
+
*
|
|
10
|
+
* Duplicate registrations for the same event type keep the first handler
|
|
11
|
+
* and emit a `console.warn`. Build-time tooling will surface this as an
|
|
12
|
+
* error.
|
|
13
|
+
*/
|
|
14
|
+
export declare function OnEvent<T extends keyof KnownEventTypes & string>(type: T): MethodDecorator;
|
|
15
|
+
export declare function OnEvent(type: string): MethodDecorator;
|
|
16
|
+
/**
|
|
17
|
+
* A lifecycle decorator that supports both bare (`@OnStart`) and factory
|
|
18
|
+
* (`@OnStart()`) call forms. The bare form applies the decorator directly;
|
|
19
|
+
* the factory form returns a new decorator. Both land the same metadata.
|
|
20
|
+
*/
|
|
21
|
+
export type DualLifecycleDecorator = MethodDecorator & (() => MethodDecorator);
|
|
22
|
+
/**
|
|
23
|
+
* Mark an instance method as the agent's `start` lifecycle hook. Called
|
|
24
|
+
* by the runtime once the agent instance has been wired with its
|
|
25
|
+
* {@link Context} and before any events are dispatched.
|
|
26
|
+
*
|
|
27
|
+
* Both bare (`@OnStart`) and factory (`@OnStart()`) forms are supported.
|
|
28
|
+
*/
|
|
29
|
+
export declare const OnStart: DualLifecycleDecorator;
|
|
30
|
+
/**
|
|
31
|
+
* Mark an instance method as the agent's `close` lifecycle hook. Called
|
|
32
|
+
* by the runtime when the agent instance is being shut down (revoked,
|
|
33
|
+
* idle-timed-out, closed by itself, or failed).
|
|
34
|
+
*
|
|
35
|
+
* Both bare (`@OnClose`) and factory (`@OnClose()`) forms are supported.
|
|
36
|
+
*/
|
|
37
|
+
export declare const OnClose: DualLifecycleDecorator;
|
|
38
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAsBlD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,eAAe,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,eAAe,CAAC;AAC5F,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;AAevD;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG,CAAC,MAAM,eAAe,CAAC,CAAC;AAoB/E;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,EAAE,sBAAwD,CAAC;AAE/E;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,EAAE,sBAAwD,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ENGAGEMENT_METADATA } from "./symbols.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve (or lazily create) the {@link EngagementMeta} record on a class.
|
|
4
|
+
*
|
|
5
|
+
* Method decorators run with `target` bound to the prototype for instance
|
|
6
|
+
* methods, so we attach metadata to `target.constructor` (the class itself).
|
|
7
|
+
* This keeps the metadata reachable as `MyEngagement[ENGAGEMENT_METADATA]`
|
|
8
|
+
* from outside, and shares the slot with `@Engagement` (which writes to the
|
|
9
|
+
* constructor directly).
|
|
10
|
+
*/
|
|
11
|
+
function ensureMeta(target) {
|
|
12
|
+
const ctor = target.constructor;
|
|
13
|
+
if (!ctor[ENGAGEMENT_METADATA]) {
|
|
14
|
+
ctor[ENGAGEMENT_METADATA] = {
|
|
15
|
+
events: {},
|
|
16
|
+
lifecycle: {},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return ctor[ENGAGEMENT_METADATA];
|
|
20
|
+
}
|
|
21
|
+
export function OnEvent(type) {
|
|
22
|
+
return (target, propertyKey) => {
|
|
23
|
+
const meta = ensureMeta(target);
|
|
24
|
+
if (meta.events[type]) {
|
|
25
|
+
// Build-time tooling will error on duplicates; at runtime, first wins.
|
|
26
|
+
console.warn(`[@cef-ai/agent-sdk] duplicate handler for "${type}" (kept: ${meta.events[type]})`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
meta.events[type] = String(propertyKey);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function makeLifecycleDecorator(field) {
|
|
33
|
+
const apply = (target, propertyKey) => {
|
|
34
|
+
const meta = ensureMeta(target);
|
|
35
|
+
(meta.lifecycle ??= {})[field] = String(propertyKey);
|
|
36
|
+
};
|
|
37
|
+
function dual(...args) {
|
|
38
|
+
if (args.length === 0)
|
|
39
|
+
return apply;
|
|
40
|
+
return apply(...args);
|
|
41
|
+
}
|
|
42
|
+
return dual;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mark an instance method as the agent's `start` lifecycle hook. Called
|
|
46
|
+
* by the runtime once the agent instance has been wired with its
|
|
47
|
+
* {@link Context} and before any events are dispatched.
|
|
48
|
+
*
|
|
49
|
+
* Both bare (`@OnStart`) and factory (`@OnStart()`) forms are supported.
|
|
50
|
+
*/
|
|
51
|
+
export const OnStart = makeLifecycleDecorator("start");
|
|
52
|
+
/**
|
|
53
|
+
* Mark an instance method as the agent's `close` lifecycle hook. Called
|
|
54
|
+
* by the runtime when the agent instance is being shut down (revoked,
|
|
55
|
+
* idle-timed-out, closed by itself, or failed).
|
|
56
|
+
*
|
|
57
|
+
* Both bare (`@OnClose`) and factory (`@OnClose()`) forms are supported.
|
|
58
|
+
*/
|
|
59
|
+
export const OnClose = makeLifecycleDecorator("close");
|
|
60
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,MAAM,cAAc,CAAC;AAGxE;;;;;;;;GAQG;AACH,SAAS,UAAU,CAAC,MAAW;IAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC;IAChC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC/B,IAAI,CAAC,mBAAmB,CAAC,GAAG;YAC1B,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;SACW,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC;AACnC,CAAC;AAgBD,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,uEAAuE;YACvE,OAAO,CAAC,IAAI,CACV,8CAA8C,IAAI,YAAY,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CACnF,CAAC;YACF,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC;AASD,SAAS,sBAAsB,CAAC,KAAwB;IACtD,MAAM,KAAK,GAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QACrD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,IAAI,CAAC,SAAS,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC;IAOF,SAAS,IAAI,CAAC,GAAG,IAAW;QAC1B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACpC,OAAQ,KAA8B,CAAC,GAAG,IAAI,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,IAA8B,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAA2B,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAA2B,sBAAsB,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface EngagementOptions {
|
|
2
|
+
/** Stable identifier for this engagement within its agent. */
|
|
3
|
+
id: string;
|
|
4
|
+
/** Human-readable goal — what this engagement is for. */
|
|
5
|
+
goal: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Mark a class as an Engagement. Sets `id` and `goal` on the metadata slot;
|
|
9
|
+
* composes with `@OnEvent` / `@OnStart` / `@OnClose` regardless of decorator
|
|
10
|
+
* application order.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Engagement(opts: EngagementOptions): ClassDecorator;
|
|
13
|
+
//# sourceMappingURL=engagement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engagement.d.ts","sourceRoot":"","sources":["../src/engagement.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAC;IACX,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;CACd;AAmBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,CAMlE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@Engagement(opts)` — class decorator that marks a class as an Engagement
|
|
3
|
+
* (goal-bound code unit inside an Agent, per ADR-019).
|
|
4
|
+
*
|
|
5
|
+
* Stores `id` and `goal` on the same {@link ENGAGEMENT_METADATA} slot the
|
|
6
|
+
* method decorators (`@OnEvent` / `@OnStart` / `@OnClose`) write to. The two
|
|
7
|
+
* decorator families are order-independent: applying `@Engagement` before or
|
|
8
|
+
* after the method decorators yields identical metadata, since both lazily
|
|
9
|
+
* initialise the slot if it doesn't already exist.
|
|
10
|
+
*/
|
|
11
|
+
import { ENGAGEMENT_METADATA } from "./symbols.js";
|
|
12
|
+
/**
|
|
13
|
+
* Resolve (or lazily create) the {@link EngagementMeta} record on a class.
|
|
14
|
+
*
|
|
15
|
+
* Class decorators receive the constructor as `target`, so we attach
|
|
16
|
+
* metadata directly. (Method decorators in `decorators.ts` get the prototype
|
|
17
|
+
* and walk to `target.constructor` — both paths land on the same slot.)
|
|
18
|
+
*/
|
|
19
|
+
function ensureMeta(target) {
|
|
20
|
+
if (!target[ENGAGEMENT_METADATA]) {
|
|
21
|
+
target[ENGAGEMENT_METADATA] = {
|
|
22
|
+
events: {},
|
|
23
|
+
lifecycle: {},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return target[ENGAGEMENT_METADATA];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Mark a class as an Engagement. Sets `id` and `goal` on the metadata slot;
|
|
30
|
+
* composes with `@OnEvent` / `@OnStart` / `@OnClose` regardless of decorator
|
|
31
|
+
* application order.
|
|
32
|
+
*/
|
|
33
|
+
export function Engagement(opts) {
|
|
34
|
+
return ((target) => {
|
|
35
|
+
const meta = ensureMeta(target);
|
|
36
|
+
meta.id = opts.id;
|
|
37
|
+
meta.goal = opts.goal;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=engagement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engagement.js","sourceRoot":"","sources":["../src/engagement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,mBAAmB,EAAuB,MAAM,cAAc,CAAC;AASxE;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,MAAW;IAC7B,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,mBAAmB,CAAC,GAAG;YAC5B,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;SACW,CAAC;IAC7B,CAAC;IACD,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAuB;IAChD,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;QACtB,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC,CAAmB,CAAC;AACvB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { OnEvent, OnStart, OnClose } from "./decorators.js";
|
|
2
|
+
export { Engagement } from "./engagement.js";
|
|
3
|
+
export type { EngagementOptions } from "./engagement.js";
|
|
4
|
+
export { ENGAGEMENT_METADATA, type EngagementMeta } from "./symbols.js";
|
|
5
|
+
export type { Context, CubbyHandle, Event, FetchInit, KnownEventTypes, Logger, ModelHandle, OnCloseReason, } from "./types.js";
|
|
6
|
+
export type { AgentCard, CubbyDecl, JSONSchema, Rule, SettingDecl, Targeting, TargetingEngagement, } from "./config/define-agent.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AACxE,YAAY,EACV,OAAO,EACP,WAAW,EACX,KAAK,EACL,SAAS,EACT,eAAe,EACf,MAAM,EACN,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAC;AAIpB,YAAY,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,IAAI,EACJ,WAAW,EACX,SAAS,EACT,mBAAmB,GACpB,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAuB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global registered symbol used to attach engagement metadata (event/lifecycle
|
|
3
|
+
* handler maps + engagement id/goal) to a class. Using `Symbol.for` ensures the
|
|
4
|
+
* same symbol is shared even if `@cef-ai/agent-sdk` is loaded from multiple
|
|
5
|
+
* locations (e.g. the agent author's bundle and the runtime that introspects it).
|
|
6
|
+
*
|
|
7
|
+
* Per ADR-019, an Engagement is a goal-bound code unit inside an Agent. The
|
|
8
|
+
* `@Engagement` class decorator and `@OnEvent` / `@OnStart` / `@OnClose` method
|
|
9
|
+
* decorators all write to this same slot on the class constructor.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ENGAGEMENT_METADATA: unique symbol;
|
|
12
|
+
export type ENGAGEMENT_METADATA = typeof ENGAGEMENT_METADATA;
|
|
13
|
+
/**
|
|
14
|
+
* Shape of the metadata object that `@Engagement` / `@OnEvent` / `@OnStart` /
|
|
15
|
+
* `@OnClose` decorators attach to a class via {@link ENGAGEMENT_METADATA}.
|
|
16
|
+
*
|
|
17
|
+
* - `id` / `goal` are set by `@Engagement(opts)`. Undefined for v0.1.0-style
|
|
18
|
+
* classes that only use the method decorators (transitional — H2 will gate
|
|
19
|
+
* manifest emission on whether `@Engagement` was applied).
|
|
20
|
+
* - `events[type]` is the method name that handles event `type`.
|
|
21
|
+
* - `lifecycle.start` / `lifecycle.close` are method names for the
|
|
22
|
+
* start/close lifecycle hooks.
|
|
23
|
+
*/
|
|
24
|
+
export interface EngagementMeta {
|
|
25
|
+
id?: string;
|
|
26
|
+
goal?: string;
|
|
27
|
+
events: Record<string, string>;
|
|
28
|
+
lifecycle?: {
|
|
29
|
+
start?: string;
|
|
30
|
+
close?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=symbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../src/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,OAAO,MAExC,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD"}
|
package/dist/symbols.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global registered symbol used to attach engagement metadata (event/lifecycle
|
|
3
|
+
* handler maps + engagement id/goal) to a class. Using `Symbol.for` ensures the
|
|
4
|
+
* same symbol is shared even if `@cef-ai/agent-sdk` is loaded from multiple
|
|
5
|
+
* locations (e.g. the agent author's bundle and the runtime that introspects it).
|
|
6
|
+
*
|
|
7
|
+
* Per ADR-019, an Engagement is a goal-bound code unit inside an Agent. The
|
|
8
|
+
* `@Engagement` class decorator and `@OnEvent` / `@OnStart` / `@OnClose` method
|
|
9
|
+
* decorators all write to this same slot on the class constructor.
|
|
10
|
+
*/
|
|
11
|
+
export const ENGAGEMENT_METADATA = Symbol.for("@cef-ai/agent-sdk/engagement-metadata");
|
|
12
|
+
//# sourceMappingURL=symbols.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../src/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAkB,MAAM,CAAC,GAAG,CAC1D,uCAAuC,CACxC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type surface for `@cef-ai/agent-sdk`.
|
|
3
|
+
*
|
|
4
|
+
* Sources of truth:
|
|
5
|
+
* - `sdk-runtime-integration-contract.md` §3 (ctx surface) and §4 (close
|
|
6
|
+
* reasons) — newer, authoritative for the `Context` shape.
|
|
7
|
+
* - `agent-sdk.md` §4 — Event / CubbyHandle / ModelHandle shapes.
|
|
8
|
+
*
|
|
9
|
+
* No imports: this module is purely declarative so it can be consumed
|
|
10
|
+
* by both the SDK runtime and downstream agent code without pulling in
|
|
11
|
+
* implementation modules.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Declaration-merged interface listing the event types known to a given
|
|
15
|
+
* agent build. Populated by the typegen step from the agent manifest;
|
|
16
|
+
* empty by default.
|
|
17
|
+
*
|
|
18
|
+
* Authors / typegen extend it via:
|
|
19
|
+
* ```ts
|
|
20
|
+
* declare module "@cef-ai/agent-sdk" {
|
|
21
|
+
* interface KnownEventTypes {
|
|
22
|
+
* user_message: { text: string };
|
|
23
|
+
* tool_result: { id: string; output: unknown };
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Consumed by `@OnEvent` and `ctx.publish` to provide string-literal
|
|
29
|
+
* autocompletion and payload typing.
|
|
30
|
+
*/
|
|
31
|
+
export interface KnownEventTypes {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An event flowing through the runtime. `from` identifies the publisher
|
|
35
|
+
* (agent id or external source); `ts` is a unix-millis timestamp.
|
|
36
|
+
*/
|
|
37
|
+
export interface Event<P = unknown> {
|
|
38
|
+
id: string;
|
|
39
|
+
type: string;
|
|
40
|
+
ts: number;
|
|
41
|
+
from: string;
|
|
42
|
+
payload: P;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Handle returned by `ctx.cubby(alias)` — a typed, scoped SQLite-style
|
|
46
|
+
* key/value store bound to the agent instance.
|
|
47
|
+
*/
|
|
48
|
+
export interface CubbyHandle {
|
|
49
|
+
query<T = unknown>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
50
|
+
exec(sql: string, params?: unknown[]): Promise<{
|
|
51
|
+
changes: number;
|
|
52
|
+
lastInsertRowid: number | bigint;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Handle for invoking a model bound to the agent under an alias declared
|
|
57
|
+
* in its manifest. `infer` is single-shot; `stream` yields chunks of the
|
|
58
|
+
* same output type.
|
|
59
|
+
*
|
|
60
|
+
* `I` is the input shape; `O` is the output (or stream chunk) shape.
|
|
61
|
+
* Defaults to `unknown` so the same handle type composes with raw SDKs.
|
|
62
|
+
*/
|
|
63
|
+
export interface ModelHandle<I = unknown, O = unknown> {
|
|
64
|
+
infer(input: I): Promise<O>;
|
|
65
|
+
stream(input: I): AsyncIterable<O>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Structured logger exposed as `ctx.log`. `fields` is merged into the
|
|
69
|
+
* log record by the runtime.
|
|
70
|
+
*
|
|
71
|
+
* (Spec history: `agent-sdk.md` §4 had `ctx.log(...args)`; the
|
|
72
|
+
* sdk-runtime-integration-contract supersedes that with this leveled
|
|
73
|
+
* shape.)
|
|
74
|
+
*/
|
|
75
|
+
export interface Logger {
|
|
76
|
+
info(msg: string, fields?: Record<string, unknown>): void;
|
|
77
|
+
warn(msg: string, fields?: Record<string, unknown>): void;
|
|
78
|
+
error(msg: string, fields?: Record<string, unknown>): void;
|
|
79
|
+
debug(msg: string, fields?: Record<string, unknown>): void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reason passed to the `@OnClose` handler by the runtime, per
|
|
83
|
+
* sdk-runtime-integration-contract §4.
|
|
84
|
+
*
|
|
85
|
+
* - `"revoked"` — capability/credential revoked by the platform.
|
|
86
|
+
* - `"idle_timeout"` — no events for the configured idle window.
|
|
87
|
+
* - `"closed_by_agent"`— agent invoked `ctx.close()`.
|
|
88
|
+
* - `"failed"` — the runtime is tearing the agent down after an error.
|
|
89
|
+
*/
|
|
90
|
+
export type OnCloseReason = "revoked" | "idle_timeout" | "closed_by_agent" | "failed";
|
|
91
|
+
/**
|
|
92
|
+
* Subset of the standard `RequestInit` that the runtime's sandboxed
|
|
93
|
+
* `ctx.fetch` accepts. Bodies are restricted to strings or raw bytes
|
|
94
|
+
* (no streams, FormData, or Blobs) to keep the cross-isolate marshalling
|
|
95
|
+
* predictable.
|
|
96
|
+
*/
|
|
97
|
+
export interface FetchInit {
|
|
98
|
+
method?: string;
|
|
99
|
+
headers?: Record<string, string>;
|
|
100
|
+
body?: string | Uint8Array | null;
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The single object passed to lifecycle / event handlers. Surface defined
|
|
105
|
+
* by sdk-runtime-integration-contract §3.
|
|
106
|
+
*
|
|
107
|
+
* `publish` is overloaded so authors with typegen-populated
|
|
108
|
+
* {@link KnownEventTypes} get payload-typed publishes; the fallback
|
|
109
|
+
* untyped overload accepts any string event type.
|
|
110
|
+
*/
|
|
111
|
+
export interface Context {
|
|
112
|
+
/** Per-alias scoped storage handle. */
|
|
113
|
+
cubby(alias: string): CubbyHandle;
|
|
114
|
+
/** Map of model handles keyed by manifest-declared alias. */
|
|
115
|
+
models: Record<string, ModelHandle>;
|
|
116
|
+
/** Sandboxed HTTP fetch. */
|
|
117
|
+
fetch(url: string | URL, init?: FetchInit): Promise<Response>;
|
|
118
|
+
/** Publish a typed event. */
|
|
119
|
+
publish<T extends keyof KnownEventTypes & string>(type: T, payload: KnownEventTypes[T]): Promise<void>;
|
|
120
|
+
/** Publish an event with an arbitrary string type. */
|
|
121
|
+
publish(type: string, payload: unknown): Promise<void>;
|
|
122
|
+
/** Frozen settings record from the agent manifest. */
|
|
123
|
+
settings: Readonly<Record<string, unknown>>;
|
|
124
|
+
/** Ask the runtime to close this agent. `reason` is surfaced to telemetry. */
|
|
125
|
+
close(reason?: string): Promise<void>;
|
|
126
|
+
/** Structured logger (see {@link Logger}). */
|
|
127
|
+
log: Logger;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,eAAe;CAAG;AAEnC;;;GAGG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,GAAG,OAAO;IAChC,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ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type surface for `@cef-ai/agent-sdk`.
|
|
3
|
+
*
|
|
4
|
+
* Sources of truth:
|
|
5
|
+
* - `sdk-runtime-integration-contract.md` §3 (ctx surface) and §4 (close
|
|
6
|
+
* reasons) — newer, authoritative for the `Context` shape.
|
|
7
|
+
* - `agent-sdk.md` §4 — Event / CubbyHandle / ModelHandle shapes.
|
|
8
|
+
*
|
|
9
|
+
* No imports: this module is purely declarative so it can be consumed
|
|
10
|
+
* by both the SDK runtime and downstream agent code without pulling in
|
|
11
|
+
* implementation modules.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cef-ai/agent-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./config": {
|
|
13
|
+
"types": "./dist/config/index.d.ts",
|
|
14
|
+
"default": "./dist/config/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^20.0.0",
|
|
25
|
+
"typescript": "^5.4.0",
|
|
26
|
+
"vitest": "^1.5.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -b",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"lint": "eslint src"
|
|
32
|
+
}
|
|
33
|
+
}
|