@loopingai/core 0.3.1 → 0.5.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 +83 -28
- package/dist/a2a/caller.d.ts +24 -0
- package/dist/a2a/caller.d.ts.map +1 -0
- package/dist/a2a/caller.js +34 -0
- package/dist/a2a/caller.js.map +1 -0
- package/dist/a2a/card.d.ts +7 -2
- package/dist/a2a/card.d.ts.map +1 -1
- package/dist/a2a/card.js +16 -7
- package/dist/a2a/card.js.map +1 -1
- package/dist/a2a/index.d.ts +15 -0
- package/dist/a2a/index.d.ts.map +1 -1
- package/dist/a2a/index.js +15 -0
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/notify.d.ts +27 -5
- package/dist/a2a/notify.d.ts.map +1 -1
- package/dist/a2a/notify.js +18 -8
- package/dist/a2a/notify.js.map +1 -1
- package/dist/a2a/push.d.ts +71 -0
- package/dist/a2a/push.d.ts.map +1 -0
- package/dist/a2a/push.js +54 -0
- package/dist/a2a/push.js.map +1 -0
- package/dist/a2a/verify.d.ts +28 -36
- package/dist/a2a/verify.d.ts.map +1 -1
- package/dist/a2a/verify.js +20 -25
- package/dist/a2a/verify.js.map +1 -1
- package/dist/agent/index.d.ts +16 -5
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +16 -5
- package/dist/agent/index.js.map +1 -1
- package/dist/config.d.ts +49 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +25 -3
- package/dist/config.js.map +1 -1
- package/dist/contract/recipe.d.ts +14 -2
- package/dist/contract/recipe.d.ts.map +1 -1
- package/dist/contract/validation.d.ts +22 -18
- package/dist/contract/validation.d.ts.map +1 -1
- package/dist/contract/validation.js +19 -10
- package/dist/contract/validation.js.map +1 -1
- package/dist/db/models/tasks.d.ts +19 -5
- package/dist/db/models/tasks.d.ts.map +1 -1
- package/dist/db/models/tasks.js +38 -8
- package/dist/db/models/tasks.js.map +1 -1
- package/dist/host/agent.d.ts +217 -0
- package/dist/host/agent.d.ts.map +1 -0
- package/dist/host/agent.js +304 -0
- package/dist/host/agent.js.map +1 -0
- package/dist/host/index.d.ts +21 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +20 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/plugin-host.d.ts +43 -0
- package/dist/host/plugin-host.d.ts.map +1 -0
- package/dist/host/plugin-host.js +2 -0
- package/dist/host/plugin-host.js.map +1 -0
- package/dist/round/agent.d.ts +267 -0
- package/dist/round/agent.d.ts.map +1 -0
- package/dist/round/agent.js +691 -0
- package/dist/round/agent.js.map +1 -0
- package/dist/round/index.d.ts +25 -0
- package/dist/round/index.d.ts.map +1 -0
- package/dist/round/index.js +24 -0
- package/dist/round/index.js.map +1 -0
- package/dist/round/policy.d.ts +99 -0
- package/dist/round/policy.d.ts.map +1 -0
- package/dist/round/policy.js +2 -0
- package/dist/round/policy.js.map +1 -0
- package/dist/round/subagent.d.ts +67 -0
- package/dist/round/subagent.d.ts.map +1 -0
- package/dist/round/subagent.js +89 -0
- package/dist/round/subagent.js.map +1 -0
- package/dist/round/turn.d.ts +231 -0
- package/dist/round/turn.d.ts.map +1 -0
- package/dist/round/turn.js +497 -0
- package/dist/round/turn.js.map +1 -0
- package/dist/round/workflow.d.ts +109 -0
- package/dist/round/workflow.d.ts.map +1 -0
- package/dist/round/workflow.js +316 -0
- package/dist/round/workflow.js.map +1 -0
- package/dist/runtime/index.d.ts +5 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -6
- package/dist/runtime/index.js.map +1 -1
- package/dist/subagent/fingerprint.d.ts.map +1 -1
- package/dist/subagent/fingerprint.js +7 -2
- package/dist/subagent/fingerprint.js.map +1 -1
- package/dist/testing/auth.d.ts.map +1 -1
- package/dist/testing/auth.js +10 -7
- package/dist/testing/auth.js.map +1 -1
- package/dist/testing/fixtures.d.ts +17 -0
- package/dist/testing/fixtures.d.ts.map +1 -1
- package/dist/testing/fixtures.js +17 -0
- package/dist/testing/fixtures.js.map +1 -1
- package/dist/testing/harness.d.ts +98 -0
- package/dist/testing/harness.d.ts.map +1 -0
- package/dist/testing/harness.js +139 -0
- package/dist/testing/harness.js.map +1 -0
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/worker/define-agent.d.ts +124 -0
- package/dist/worker/define-agent.d.ts.map +1 -0
- package/dist/worker/define-agent.js +21 -0
- package/dist/worker/define-agent.js.map +1 -0
- package/dist/worker/index.d.ts +29 -4
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +70 -12
- package/dist/worker/index.js.map +1 -1
- package/package.json +12 -3
|
@@ -68,8 +68,16 @@ export declare function makeTasks(db: DB): {
|
|
|
68
68
|
* it. That closes the window between a workflow's terminal build and its
|
|
69
69
|
* callback — the read-check-write is synchronous here, so a `CancelTask`
|
|
70
70
|
* landing mid-delivery makes this return `false` and the notify never fires.
|
|
71
|
-
*
|
|
72
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* The reverse direction is guarded too: writing `canceled` over an already
|
|
73
|
+
* `completed`/`failed` row is refused, mirroring {@link cancel}'s own source
|
|
74
|
+
* guard. Without it, a cancellation landing between the Workflow's `complete`
|
|
75
|
+
* and `notify` steps — separate, independently-retried steps — could flip
|
|
76
|
+
* storage to canceled while `deliver()` still posts the cached completed
|
|
77
|
+
* task it already built, the exact race this guard exists to close. Writing
|
|
78
|
+
* `canceled` onto a `submitted`/`working` row, or re-writing it onto an
|
|
79
|
+
* already-`canceled` one, stays allowed: that is how the a2a-js handler's own
|
|
80
|
+
* cancel branch records the cancellation.
|
|
73
81
|
*/
|
|
74
82
|
save(task: Task): boolean;
|
|
75
83
|
/**
|
|
@@ -81,9 +89,15 @@ export declare function makeTasks(db: DB): {
|
|
|
81
89
|
*/
|
|
82
90
|
markWorking(taskId: string): "ok" | "canceled";
|
|
83
91
|
/**
|
|
84
|
-
* Flip the task to `canceled` and return it
|
|
85
|
-
*
|
|
86
|
-
*
|
|
92
|
+
* Flip the task to `canceled` and return it, or `null` if the row is not
|
|
93
|
+
* eligible — unknown, or already past `submitted`/`working`. Guarding the
|
|
94
|
+
* source state (not just the destination, as {@link save} does) matters
|
|
95
|
+
* because `complete`/`notify` are separate Workflow steps: without this, a
|
|
96
|
+
* cancellation landing between them would flip an already-`completed` or
|
|
97
|
+
* `failed` row to `canceled` right as `deliver()` posts the terminal
|
|
98
|
+
* callback it had already built, silently rewriting a delivered result.
|
|
99
|
+
* Terminal: once this lands, {@link save} refuses every non-canceled write,
|
|
100
|
+
* so no completed or failed callback can be built from this row afterwards.
|
|
87
101
|
*/
|
|
88
102
|
cancel(taskId: string): PlainTask | null;
|
|
89
103
|
/** Delete all tasks older than 30 days (called by the maintenance cron). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../../src/db/models/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAMnC,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GA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;QACf,SAAS,EAAE,MAAM,CAAC;KACnB,GAAG,SAAS;IAwBb,6EAA6E;gBACjE,MAAM,GAAG,SAAS,GAAG,IAAI;IAIrC;;;OAGG;gBACS,aAAa,GAAG;QAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAiCrE;;;;;;;;;;;;;;;;;;;OAmBG;eACQ,IAAI,GAAG,OAAO;IA0BzB;;;;;;OAMG;wBACiB,MAAM,GAAG,IAAI,GAAG,UAAU;IAe9C;;;;;;;;;;OAUG;mBACY,MAAM,GAAG,SAAS,GAAG,IAAI;IAoBxC,4EAA4E;eACjE,IAAI;EAKlB"}
|
package/dist/db/models/tasks.js
CHANGED
|
@@ -133,14 +133,33 @@ export function makeTasks(db) {
|
|
|
133
133
|
* it. That closes the window between a workflow's terminal build and its
|
|
134
134
|
* callback — the read-check-write is synchronous here, so a `CancelTask`
|
|
135
135
|
* landing mid-delivery makes this return `false` and the notify never fires.
|
|
136
|
-
*
|
|
137
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* The reverse direction is guarded too: writing `canceled` over an already
|
|
138
|
+
* `completed`/`failed` row is refused, mirroring {@link cancel}'s own source
|
|
139
|
+
* guard. Without it, a cancellation landing between the Workflow's `complete`
|
|
140
|
+
* and `notify` steps — separate, independently-retried steps — could flip
|
|
141
|
+
* storage to canceled while `deliver()` still posts the cached completed
|
|
142
|
+
* task it already built, the exact race this guard exists to close. Writing
|
|
143
|
+
* `canceled` onto a `submitted`/`working` row, or re-writing it onto an
|
|
144
|
+
* already-`canceled` one, stays allowed: that is how the a2a-js handler's own
|
|
145
|
+
* cancel branch records the cancellation.
|
|
138
146
|
*/
|
|
139
147
|
save(task) {
|
|
140
148
|
const existing = readOne(task.id);
|
|
141
|
-
if (existing
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
if (existing === null) {
|
|
150
|
+
upsert(task);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
const existingState = stateOf(existing);
|
|
154
|
+
const incomingState = stateOf(task);
|
|
155
|
+
if (existingState === TaskState.TASK_STATE_CANCELED &&
|
|
156
|
+
incomingState !== TaskState.TASK_STATE_CANCELED) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (incomingState === TaskState.TASK_STATE_CANCELED &&
|
|
160
|
+
existingState !== TaskState.TASK_STATE_SUBMITTED &&
|
|
161
|
+
existingState !== TaskState.TASK_STATE_WORKING &&
|
|
162
|
+
existingState !== TaskState.TASK_STATE_CANCELED) {
|
|
144
163
|
return false;
|
|
145
164
|
}
|
|
146
165
|
upsert(task);
|
|
@@ -171,14 +190,25 @@ export function makeTasks(db) {
|
|
|
171
190
|
return "ok";
|
|
172
191
|
},
|
|
173
192
|
/**
|
|
174
|
-
* Flip the task to `canceled` and return it
|
|
175
|
-
*
|
|
176
|
-
*
|
|
193
|
+
* Flip the task to `canceled` and return it, or `null` if the row is not
|
|
194
|
+
* eligible — unknown, or already past `submitted`/`working`. Guarding the
|
|
195
|
+
* source state (not just the destination, as {@link save} does) matters
|
|
196
|
+
* because `complete`/`notify` are separate Workflow steps: without this, a
|
|
197
|
+
* cancellation landing between them would flip an already-`completed` or
|
|
198
|
+
* `failed` row to `canceled` right as `deliver()` posts the terminal
|
|
199
|
+
* callback it had already built, silently rewriting a delivered result.
|
|
200
|
+
* Terminal: once this lands, {@link save} refuses every non-canceled write,
|
|
201
|
+
* so no completed or failed callback can be built from this row afterwards.
|
|
177
202
|
*/
|
|
178
203
|
cancel(taskId) {
|
|
179
204
|
const task = readOne(taskId);
|
|
180
205
|
if (!task)
|
|
181
206
|
return null;
|
|
207
|
+
const state = stateOf(task);
|
|
208
|
+
if (state !== TaskState.TASK_STATE_SUBMITTED &&
|
|
209
|
+
state !== TaskState.TASK_STATE_WORKING) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
182
212
|
task.status = {
|
|
183
213
|
...task.status,
|
|
184
214
|
state: TaskState.TASK_STATE_CANCEL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EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;QAC/D,OAAO,EACL,KAAK,CAAC,aAAa,KAAK,SAAS;YAC/B,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;KACvE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { Agent, type Schedule } from "agents";
|
|
2
|
+
import { type Task } from "@a2a-js/sdk";
|
|
3
|
+
import { type AgentRuntime } from "../runtime/index.js";
|
|
4
|
+
import type { AgentPlugin } from "../contract/plugin.js";
|
|
5
|
+
import { type CoreConfig, type CoreConfigOverrides } from "../config.js";
|
|
6
|
+
import type { A2ASecretsEnv, AiEnv } from "../env.js";
|
|
7
|
+
import { AgentDB } from "../db/index.js";
|
|
8
|
+
import type { GatewayIdentity } from "../a2a/verify.js";
|
|
9
|
+
import type { PlainTask } from "../a2a/task.js";
|
|
10
|
+
import type { TaskListQuery } from "../a2a/agent-stub.js";
|
|
11
|
+
import { type PushChannel, type TurnPushContext } from "../a2a/push.js";
|
|
12
|
+
import { type SessionLike } from "../agent/session.js";
|
|
13
|
+
import { type GatewayMetadata, type ModelPair, type ModelRuntime } from "../agent/model.js";
|
|
14
|
+
import type { PluginHost } from "./plugin-host.js";
|
|
15
|
+
/**
|
|
16
|
+
* The Durable Object body every Looping agent has, whatever loop it runs.
|
|
17
|
+
*
|
|
18
|
+
* ## Why this is core's and not the app's
|
|
19
|
+
*
|
|
20
|
+
* It was the app's, in the starter, and it was written twice — once for the
|
|
21
|
+
* delegating round agent, once for the single-turn proactive one. The two copies
|
|
22
|
+
* were identical for ~180 lines: the memoized runtime/db/models getters, the
|
|
23
|
+
* `onStart` that must await migrations before the SDK dispatches any RPC, the
|
|
24
|
+
* cron registration guard, the session with its displacement fan-out, the
|
|
25
|
+
* `identityKey` timing, and the task RPC surface.
|
|
26
|
+
*
|
|
27
|
+
* They did not stay identical. The second copy dropped `markWorking`'s
|
|
28
|
+
* cancellation verdict on the floor and probed with a separate `getTask` before
|
|
29
|
+
* writing a terminal Task — so a canceled task still burned a model call, and the
|
|
30
|
+
* gateway could still receive a `completed` callback for a task the caller had
|
|
31
|
+
* abandoned. Both are lifecycle invariants, both were documented in the first
|
|
32
|
+
* copy, and neither is visible to a type checker or a linter.
|
|
33
|
+
*
|
|
34
|
+
* That is the argument for this class. **None of it is policy.** How a turn is
|
|
35
|
+
* shaped, what ends it, what the model is told — all of that stays with the
|
|
36
|
+
* agent, and an agent that wants a different loop simply does not extend
|
|
37
|
+
* {@link file://../round/agent.ts RoundAgentBase}. What is here is the part where
|
|
38
|
+
* being different is only ever a bug.
|
|
39
|
+
*
|
|
40
|
+
* ## The three seams
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* export class MyAgent extends LoopingAgent<Env> {
|
|
44
|
+
* protected agentConfig() { return MY_CONFIG; }
|
|
45
|
+
* protected agentPlugins(host: PluginHost<Env>) { return plugins(host); }
|
|
46
|
+
* protected agentSoul(capabilities: string) { return soulPrompt(capabilities); }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* One Durable Object instance per verified caller (keyed by the gateway JWT's
|
|
51
|
+
* `identity.key`), each owning **one continuous Session** — durable history plus
|
|
52
|
+
* a self-edited `memory` block, backed by `this.sql`. All of a caller's turns, in
|
|
53
|
+
* any channel or thread, accumulate into that one conversation.
|
|
54
|
+
*/
|
|
55
|
+
export declare abstract class LoopingAgent<TEnv extends Cloudflare.Env & AiEnv & A2ASecretsEnv = Cloudflare.Env & AiEnv & A2ASecretsEnv> extends Agent<TEnv> {
|
|
56
|
+
private session?;
|
|
57
|
+
private _runtime?;
|
|
58
|
+
private _models?;
|
|
59
|
+
private _pair?;
|
|
60
|
+
private _db?;
|
|
61
|
+
/**
|
|
62
|
+
* The verified caller this instance belongs to, set on the first turn.
|
|
63
|
+
*
|
|
64
|
+
* `onStart` runs before any request, so it is not known when `agentPlugins()`
|
|
65
|
+
* is built — which is why anything per-caller takes a thunk. The DO is keyed
|
|
66
|
+
* 1:1 by this value, so it is constant once set.
|
|
67
|
+
*/
|
|
68
|
+
private identityKey?;
|
|
69
|
+
/**
|
|
70
|
+
* Test-only model injection. A **field**, not a constructor argument or an RPC
|
|
71
|
+
* parameter, so it never appears on the generated DO stub: production callers
|
|
72
|
+
* cannot reach it, and no model configuration crosses the RPC boundary.
|
|
73
|
+
*/
|
|
74
|
+
modelsOverride?: ModelPair;
|
|
75
|
+
/** This agent's config overrides. Merged onto core's baseline once, at start. */
|
|
76
|
+
protected abstract agentConfig(): CoreConfigOverrides;
|
|
77
|
+
/** This agent's installed capabilities. Conventionally its `./plugins.ts`. */
|
|
78
|
+
protected abstract agentPlugins(host: PluginHost<TEnv>): AgentPlugin[];
|
|
79
|
+
/**
|
|
80
|
+
* This agent's identity, with the installed plugins' capability blocks already
|
|
81
|
+
* rendered in. Core ships no prompt copy — this is yours to write.
|
|
82
|
+
*/
|
|
83
|
+
protected abstract agentSoul(capabilities: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Everything that would otherwise be a module-level constant, resolved once
|
|
86
|
+
* per DO instance from this agent's config and its installed plugins.
|
|
87
|
+
*
|
|
88
|
+
* Resolving a registry at *import* time is the one thing the package split
|
|
89
|
+
* exists to prevent: it freezes the registry before `env` exists (which on
|
|
90
|
+
* Workers is always), defeats tree-shaking, and makes per-agent plugin
|
|
91
|
+
* selection impossible.
|
|
92
|
+
*/
|
|
93
|
+
protected get runtime(): AgentRuntime;
|
|
94
|
+
/** The resolved config. */
|
|
95
|
+
protected get config(): CoreConfig;
|
|
96
|
+
/** The agent's database (drizzle + migrations), built once per DO instance. */
|
|
97
|
+
protected get db(): AgentDB;
|
|
98
|
+
/** The model runtime for this instance, built lazily over the `AI` binding. */
|
|
99
|
+
protected get models(): ModelRuntime;
|
|
100
|
+
/**
|
|
101
|
+
* What this agent's plugins are handed. Built from
|
|
102
|
+
* {@link resolvedModelIds} rather than `this.config`, which would be a cycle —
|
|
103
|
+
* building the runtime is what needs these.
|
|
104
|
+
*/
|
|
105
|
+
protected pluginHost(): PluginHost<TEnv>;
|
|
106
|
+
/**
|
|
107
|
+
* The model settings a locally-declared recipe runs on, resolved *before* the
|
|
108
|
+
* runtime exists.
|
|
109
|
+
*
|
|
110
|
+
* Deliberately not `this.config` — that would be a cycle. `resolveConfig` is
|
|
111
|
+
* cheap and pure and fills in core's baseline, so this is the same result the
|
|
112
|
+
* runtime lands on; that matters because every recipe runs on exactly this
|
|
113
|
+
* pair — `RecipePolicy` carries it and `validateRecipe` stamps it on.
|
|
114
|
+
*/
|
|
115
|
+
private resolvedModelIds;
|
|
116
|
+
onStart(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Cron handler: delete task rows older than 30 days. Runs Sunday 01:00 UTC.
|
|
119
|
+
*
|
|
120
|
+
* A plugin's own tables are its business — core's journal does not reach them,
|
|
121
|
+
* and neither does this sweep. A subclass with more durable state of its own
|
|
122
|
+
* overrides {@link cleanupAgentState}.
|
|
123
|
+
*/
|
|
124
|
+
cleanupOldTasks(_payload: Record<string, never>, _schedule: Schedule): Promise<void>;
|
|
125
|
+
/** Extra durable state to age out alongside the task rows. Default: none. */
|
|
126
|
+
protected cleanupAgentState(): void;
|
|
127
|
+
/**
|
|
128
|
+
* The main agent's primary/fallback pair. With `metadata` it builds a fresh
|
|
129
|
+
* pair carrying that AI Gateway correlation tag (so a gateway log ties the call
|
|
130
|
+
* to its task and round); without it — the Session's own compaction model — it
|
|
131
|
+
* reuses a memoized default. A test `modelsOverride` always wins.
|
|
132
|
+
*/
|
|
133
|
+
protected modelPair(metadata?: GatewayMetadata): ModelPair;
|
|
134
|
+
/**
|
|
135
|
+
* The one continuous Session for this caller (rebuilt from `this.sql` after
|
|
136
|
+
* eviction). Memoized — `identity` is constant for the DO's life, since the DO
|
|
137
|
+
* is keyed 1:1 by `identity.key`.
|
|
138
|
+
*
|
|
139
|
+
* `onMessagesDisplaced` is the whole integration for anything that wants the
|
|
140
|
+
* messages a compaction folds away: core performs the compaction, so core
|
|
141
|
+
* announces the loss, and the runtime fans it out to every plugin that asked.
|
|
142
|
+
*/
|
|
143
|
+
getSession(identity: GatewayIdentity): SessionLike;
|
|
144
|
+
/** The caller key, which is present on every path that can reach a plugin. */
|
|
145
|
+
protected requireIdentityKey(): string;
|
|
146
|
+
/** The gateway callback channel for one turn. See {@link PushChannel}. */
|
|
147
|
+
protected push(context: TurnPushContext): PushChannel;
|
|
148
|
+
/**
|
|
149
|
+
* The per-request system-prompt suffix describing the verified caller.
|
|
150
|
+
*
|
|
151
|
+
* A rendering of a protocol fact rather than prompt copy, so core supplies one
|
|
152
|
+
* — see {@link callerContext}. Override it to name what a workspace id means in
|
|
153
|
+
* your deployment; do not use it to say who the *user* is, which this is not.
|
|
154
|
+
*/
|
|
155
|
+
protected callerContext(identity: GatewayIdentity): string;
|
|
156
|
+
beginTask(input: {
|
|
157
|
+
messageId: string;
|
|
158
|
+
taskId: string;
|
|
159
|
+
contextId: string;
|
|
160
|
+
}): Promise<PlainTask>;
|
|
161
|
+
getTask(taskId: string): Promise<PlainTask | null>;
|
|
162
|
+
listTasks(query: TaskListQuery): Promise<{
|
|
163
|
+
tasks: PlainTask[];
|
|
164
|
+
totalSize: number;
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Persist a Task, returning **whether the guarded write applied**.
|
|
168
|
+
*
|
|
169
|
+
* That boolean is the cancellation check, and a caller must key its callback on
|
|
170
|
+
* it: `AgentDB` refuses to write a terminal state over a `canceled` row and
|
|
171
|
+
* does that read and write in one synchronous pass inside the DO. Probing with
|
|
172
|
+
* {@link getTask} first and saving second leaves a window — between the two
|
|
173
|
+
* calls, and again between the save and the notify — in which a cancel lands
|
|
174
|
+
* and the gateway still receives a `completed` callback.
|
|
175
|
+
*
|
|
176
|
+
* A `canceled` state routes to {@link markCanceled} instead of a plain write,
|
|
177
|
+
* so a `tasks/cancel` arriving through the a2a-js TaskStore and one arriving
|
|
178
|
+
* through {@link cancelTask} converge on the same interruption path.
|
|
179
|
+
*/
|
|
180
|
+
saveTask(task: Task): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Move the Task to `working`. Returns `"canceled"` when the caller cancelled
|
|
183
|
+
* first — read it and stop, rather than probing with a separate
|
|
184
|
+
* {@link getTask}, which reopens the gap between asking and acting.
|
|
185
|
+
*
|
|
186
|
+
* Anything else is `"ok"`, including an unknown row and a row already `working`
|
|
187
|
+
* (a replayed step): only an actual cancellation stops the pipeline.
|
|
188
|
+
*/
|
|
189
|
+
markWorking(taskId: string): Promise<"ok" | "canceled">;
|
|
190
|
+
cancelTask(taskId: string): Promise<PlainTask | null>;
|
|
191
|
+
/**
|
|
192
|
+
* The one place a Task becomes canceled: flip the row — terminal, so every
|
|
193
|
+
* non-canceled write is refused afterwards — then interrupt whatever is still
|
|
194
|
+
* running for it.
|
|
195
|
+
*
|
|
196
|
+
* `task` is supplied when the caller already built the canceled Task (the
|
|
197
|
+
* a2a-js cancel branch attaches its own status message); otherwise the row's
|
|
198
|
+
* own guarded flip produces it. Both paths are guarded against the same race:
|
|
199
|
+
* a task that already reached `completed`/`failed` refuses the write, and its
|
|
200
|
+
* verdict — not a `get` read straight after, which would return that
|
|
201
|
+
* unchanged terminal row and be mistaken for a successful cancellation — is
|
|
202
|
+
* what decides whether {@link onTaskCanceled} runs at all.
|
|
203
|
+
*/
|
|
204
|
+
private markCanceled;
|
|
205
|
+
/**
|
|
206
|
+
* Interrupt work still in flight for a task that has just been canceled.
|
|
207
|
+
*
|
|
208
|
+
* Default: nothing, which is right for an agent whose turn is a single
|
|
209
|
+
* inference — the row is terminal and the next guarded write refuses. An agent
|
|
210
|
+
* with children overrides this to abort them.
|
|
211
|
+
*
|
|
212
|
+
* **Must be best-effort.** Cancellation has already been recorded by the time
|
|
213
|
+
* this runs, and it must not fail because cleanup did.
|
|
214
|
+
*/
|
|
215
|
+
protected onTaskCanceled(_taskId: string): Promise<void>;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/host/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAa,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,8BAAsB,YAAY,CAChC,IAAI,SAAS,UAAU,CAAC,GAAG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