@restatedev/agents 0.11.1 → 0.12.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 +189 -808
- package/dist/pi/factory.d.ts +73 -0
- package/dist/pi/factory.d.ts.map +1 -0
- package/dist/pi/factory.js +145 -0
- package/dist/pi/factory.js.map +1 -0
- package/dist/pi/index.d.ts +5 -129
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +31 -571
- package/dist/pi/index.js.map +1 -1
- package/dist/pi/keepalive.d.ts +3 -16
- package/dist/pi/keepalive.d.ts.map +1 -1
- package/dist/pi/keepalive.js +38 -41
- package/dist/pi/keepalive.js.map +1 -1
- package/dist/pi/left.d.ts +16 -0
- package/dist/pi/left.d.ts.map +1 -0
- package/dist/pi/left.js +23 -0
- package/dist/pi/left.js.map +1 -0
- package/dist/pi/storage.d.ts +19 -76
- package/dist/pi/storage.d.ts.map +1 -1
- package/dist/pi/storage.js +50 -368
- package/dist/pi/storage.js.map +1 -1
- package/dist/pi/tools.d.ts +12 -0
- package/dist/pi/tools.d.ts.map +1 -0
- package/dist/pi/tools.js +70 -0
- package/dist/pi/tools.js.map +1 -0
- package/package.json +11 -254
- package/src/pi/factory.ts +231 -0
- package/src/pi/index.ts +31 -759
- package/src/pi/keepalive.ts +46 -56
- package/src/pi/left.ts +52 -0
- package/src/pi/storage.ts +75 -409
- package/src/pi/tools.ts +78 -0
- package/dist/agentlib/agent.d.ts +0 -32
- package/dist/agentlib/agent.d.ts.map +0 -1
- package/dist/agentlib/agent.js +0 -174
- package/dist/agentlib/agent.js.map +0 -1
- package/dist/agentlib/index.d.ts +0 -5
- package/dist/agentlib/index.d.ts.map +0 -1
- package/dist/agentlib/index.js +0 -15
- package/dist/agentlib/index.js.map +0 -1
- package/dist/agentlib/messages.d.ts +0 -39
- package/dist/agentlib/messages.d.ts.map +0 -1
- package/dist/agentlib/messages.js +0 -177
- package/dist/agentlib/messages.js.map +0 -1
- package/dist/agentlib/model.d.ts +0 -31
- package/dist/agentlib/model.d.ts.map +0 -1
- package/dist/agentlib/model.js +0 -140
- package/dist/agentlib/model.js.map +0 -1
- package/dist/agentlib/options.d.ts +0 -58
- package/dist/agentlib/options.d.ts.map +0 -1
- package/dist/agentlib/options.js +0 -2
- package/dist/agentlib/options.js.map +0 -1
- package/dist/agentlib/runtime.d.ts +0 -37
- package/dist/agentlib/runtime.d.ts.map +0 -1
- package/dist/agentlib/runtime.js +0 -216
- package/dist/agentlib/runtime.js.map +0 -1
- package/dist/agentlib/state.d.ts +0 -114
- package/dist/agentlib/state.d.ts.map +0 -1
- package/dist/agentlib/state.js +0 -52
- package/dist/agentlib/state.js.map +0 -1
- package/dist/agentlib/steering.d.ts +0 -23
- package/dist/agentlib/steering.d.ts.map +0 -1
- package/dist/agentlib/steering.js +0 -48
- package/dist/agentlib/steering.js.map +0 -1
- package/dist/agentlib/tools.d.ts +0 -33
- package/dist/agentlib/tools.d.ts.map +0 -1
- package/dist/agentlib/tools.js +0 -245
- package/dist/agentlib/tools.js.map +0 -1
- package/dist/agentlib/turn.d.ts +0 -82
- package/dist/agentlib/turn.d.ts.map +0 -1
- package/dist/agentlib/turn.js +0 -253
- package/dist/agentlib/turn.js.map +0 -1
- package/dist/calls.d.ts +0 -90
- package/dist/calls.d.ts.map +0 -1
- package/dist/calls.js +0 -235
- package/dist/calls.js.map +0 -1
- package/dist/claude/index.d.ts +0 -106
- package/dist/claude/index.d.ts.map +0 -1
- package/dist/claude/index.js +0 -386
- package/dist/claude/index.js.map +0 -1
- package/dist/client.d.ts +0 -90
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -88
- package/dist/client.js.map +0 -1
- package/dist/common.d.ts +0 -410
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -563
- package/dist/common.js.map +0 -1
- package/dist/companion.d.ts +0 -286
- package/dist/companion.d.ts.map +0 -1
- package/dist/companion.js +0 -463
- package/dist/companion.js.map +0 -1
- package/dist/conversation.d.ts +0 -576
- package/dist/conversation.d.ts.map +0 -1
- package/dist/conversation.js +0 -1476
- package/dist/conversation.js.map +0 -1
- package/dist/deepseek/barriers.d.ts +0 -11
- package/dist/deepseek/barriers.d.ts.map +0 -1
- package/dist/deepseek/barriers.js +0 -36
- package/dist/deepseek/barriers.js.map +0 -1
- package/dist/deepseek/index.d.ts +0 -97
- package/dist/deepseek/index.d.ts.map +0 -1
- package/dist/deepseek/index.js +0 -603
- package/dist/deepseek/index.js.map +0 -1
- package/dist/deepseek/persistence.d.ts +0 -83
- package/dist/deepseek/persistence.d.ts.map +0 -1
- package/dist/deepseek/persistence.js +0 -262
- package/dist/deepseek/persistence.js.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/langgraph/checkpointer.d.ts +0 -52
- package/dist/langgraph/checkpointer.d.ts.map +0 -1
- package/dist/langgraph/checkpointer.js +0 -477
- package/dist/langgraph/checkpointer.js.map +0 -1
- package/dist/langgraph/context.d.ts +0 -10
- package/dist/langgraph/context.d.ts.map +0 -1
- package/dist/langgraph/context.js +0 -21
- package/dist/langgraph/context.js.map +0 -1
- package/dist/langgraph/errors.d.ts +0 -16
- package/dist/langgraph/errors.d.ts.map +0 -1
- package/dist/langgraph/errors.js +0 -30
- package/dist/langgraph/errors.js.map +0 -1
- package/dist/langgraph/graph.d.ts +0 -25
- package/dist/langgraph/graph.d.ts.map +0 -1
- package/dist/langgraph/graph.js +0 -378
- package/dist/langgraph/graph.js.map +0 -1
- package/dist/langgraph/index.d.ts +0 -119
- package/dist/langgraph/index.d.ts.map +0 -1
- package/dist/langgraph/index.js +0 -325
- package/dist/langgraph/index.js.map +0 -1
- package/dist/langgraph/keepalive.d.ts +0 -16
- package/dist/langgraph/keepalive.d.ts.map +0 -1
- package/dist/langgraph/keepalive.js +0 -51
- package/dist/langgraph/keepalive.js.map +0 -1
- package/dist/langgraph/nodes.d.ts +0 -71
- package/dist/langgraph/nodes.d.ts.map +0 -1
- package/dist/langgraph/nodes.js +0 -148
- package/dist/langgraph/nodes.js.map +0 -1
- package/dist/messages.d.ts +0 -18
- package/dist/messages.d.ts.map +0 -1
- package/dist/messages.js +0 -182
- package/dist/messages.js.map +0 -1
- package/dist/object.d.ts +0 -213
- package/dist/object.d.ts.map +0 -1
- package/dist/object.js +0 -309
- package/dist/object.js.map +0 -1
- package/dist/opencode/db.d.ts +0 -81
- package/dist/opencode/db.d.ts.map +0 -1
- package/dist/opencode/db.js +0 -249
- package/dist/opencode/db.js.map +0 -1
- package/dist/opencode/index.d.ts +0 -184
- package/dist/opencode/index.d.ts.map +0 -1
- package/dist/opencode/index.js +0 -1079
- package/dist/opencode/index.js.map +0 -1
- package/dist/output.d.ts +0 -25
- package/dist/output.d.ts.map +0 -1
- package/dist/output.js +0 -99
- package/dist/output.js.map +0 -1
- package/dist/pi/commits.d.ts +0 -6
- package/dist/pi/commits.d.ts.map +0 -1
- package/dist/pi/commits.js +0 -3
- package/dist/pi/commits.js.map +0 -1
- package/dist/steering.d.ts +0 -32
- package/dist/steering.d.ts.map +0 -1
- package/dist/steering.js +0 -45
- package/dist/steering.js.map +0 -1
- package/dist/tools.d.ts +0 -267
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -305
- package/dist/tools.js.map +0 -1
- package/dist/webhook.d.ts +0 -71
- package/dist/webhook.d.ts.map +0 -1
- package/dist/webhook.js +0 -102
- package/dist/webhook.js.map +0 -1
- package/src/agentlib/README.md +0 -229
- package/src/agentlib/agent.ts +0 -216
- package/src/agentlib/index.ts +0 -16
- package/src/agentlib/messages.ts +0 -207
- package/src/agentlib/model.ts +0 -156
- package/src/agentlib/options.ts +0 -62
- package/src/agentlib/runtime.ts +0 -252
- package/src/agentlib/state.ts +0 -93
- package/src/agentlib/steering.ts +0 -53
- package/src/agentlib/tools.ts +0 -355
- package/src/agentlib/turn.ts +0 -302
- package/src/calls.ts +0 -330
- package/src/claude/README.md +0 -107
- package/src/claude/index.ts +0 -487
- package/src/client.ts +0 -187
- package/src/common.ts +0 -766
- package/src/companion.ts +0 -675
- package/src/conversation.ts +0 -1799
- package/src/deepseek/README.md +0 -202
- package/src/deepseek/barriers.ts +0 -63
- package/src/deepseek/index.ts +0 -740
- package/src/deepseek/persistence.ts +0 -337
- package/src/index.ts +0 -41
- package/src/langgraph/README.md +0 -199
- package/src/langgraph/checkpointer.ts +0 -614
- package/src/langgraph/context.ts +0 -27
- package/src/langgraph/errors.ts +0 -26
- package/src/langgraph/graph.ts +0 -422
- package/src/langgraph/index.ts +0 -500
- package/src/langgraph/keepalive.ts +0 -58
- package/src/langgraph/nodes.ts +0 -247
- package/src/messages.ts +0 -244
- package/src/object.ts +0 -454
- package/src/opencode/README.md +0 -249
- package/src/opencode/db.ts +0 -387
- package/src/opencode/index.ts +0 -1339
- package/src/output.ts +0 -116
- package/src/pi/README.md +0 -174
- package/src/pi/commits.ts +0 -7
- package/src/steering.ts +0 -68
- package/src/tools.ts +0 -515
- package/src/webhook.ts +0 -161
package/dist/calls.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type * as restate from '@restatedev/sessions';
|
|
2
|
-
import { Schema } from '@restatedev/sessions/internal';
|
|
3
|
-
/**
|
|
4
|
-
* The table of the {@link Calls}: one row, of the invocation whose calls they are. `answerOnce` applies it with
|
|
5
|
-
* the conversation's, in one commit, as a key's first turn starts.
|
|
6
|
-
*/
|
|
7
|
-
export declare const SCHEMA: Schema;
|
|
8
|
-
/**
|
|
9
|
-
* Have {@link flushHeld} write, with `flush`, what a holder keeps back: by
|
|
10
|
-
* default the rows that the conversation of the attempt's turn holds back
|
|
11
|
-
* (`Conversation.hold`), which `answerOnce` sets. A holder of another `slot`
|
|
12
|
-
* (pi's storage, which holds its commits until an effect starts) coexists
|
|
13
|
-
* with it; one of the same slot replaces it, and without a `flush` the slot
|
|
14
|
-
* is released.
|
|
15
|
-
*/
|
|
16
|
-
export declare const holding: (ctx: restate.SessionContext, flush: (() => Promise<void>) | undefined, slot?: string) => void;
|
|
17
|
-
/**
|
|
18
|
-
* Write what the holders keep back, in the order they were set, one after
|
|
19
|
-
* the other: the rows that the conversation of the attempt's turn holds back,
|
|
20
|
-
* if any (see `Conversation.hold`), and pi's batched commits. Call it before
|
|
21
|
-
* what another party sees, or what outlives the attempt: a publish, a
|
|
22
|
-
* Restate call, send or wait. What is held is lost in a crash, and the
|
|
23
|
-
* retried attempt makes it again; what was seen or called must not depend
|
|
24
|
-
* on it.
|
|
25
|
-
*/
|
|
26
|
-
export declare function flushHeld(ctx: restate.SessionContext): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Run `work` (a turn's) with the calls its tools make kept as prompt
|
|
29
|
-
* `prompt`'s: they are matched, and rejoined, within it only. An invocation
|
|
30
|
-
* that prompts twice, its second prompt making the call its first made
|
|
31
|
-
* (the same tool and input), would otherwise take the first's after a crash
|
|
32
|
-
* (its record not yet forgotten), and never make its own.
|
|
33
|
-
*/
|
|
34
|
-
export declare function forPrompt<T>(ctx: restate.SessionContext, prompt: string, work: () => Promise<T>): Promise<T>;
|
|
35
|
-
/**
|
|
36
|
-
* The call of tool `tool` with `input` that tool call `callId` makes: the
|
|
37
|
-
* one it made to `tool` before (a run again), or else, if `rejoin`, the one
|
|
38
|
-
* an earlier attempt made with the same tool and input (made again under a
|
|
39
|
-
* new id), or else a new one, an `approval` its tool call waits for if so.
|
|
40
|
-
* `answered()` stores that it answered.
|
|
41
|
-
*/
|
|
42
|
-
export declare function callOf(ctx: restate.SessionContext, tool: string, input: unknown, callId: string, { rejoin, approval }?: {
|
|
43
|
-
rejoin?: boolean;
|
|
44
|
-
approval?: boolean;
|
|
45
|
-
}): Promise<{
|
|
46
|
-
id: string;
|
|
47
|
-
/**
|
|
48
|
-
* It answered, with `failed` if a terminal error answered it: kept until
|
|
49
|
-
* the transcript has its result.
|
|
50
|
-
*
|
|
51
|
-
* It rides a commit that is under way (the one that stores the call's
|
|
52
|
-
* result, when the framework's write has started), and is otherwise
|
|
53
|
-
* written on its own at once ({@link ride}): a call that answered must
|
|
54
|
-
* not stay unrecorded while something else runs (a slow tool of the same
|
|
55
|
-
* round, a call that waits for a signal). A crash before it is written
|
|
56
|
-
* reads the call as one that did not answer, as a crash just before a
|
|
57
|
-
* commit of its own would have: made again under the same key, and cut off
|
|
58
|
-
* for a stopped turn that another invocation closes ({@link outcomes} reads
|
|
59
|
-
* the stored row; the attempt's own turn reads its state).
|
|
60
|
-
*/
|
|
61
|
-
answered(failed?: string): Promise<void>;
|
|
62
|
-
}>;
|
|
63
|
-
/**
|
|
64
|
-
* Forget the calls that answered whose result the framework stored: those
|
|
65
|
-
* of which `stored(id, failed)` is true for the last id they were made with,
|
|
66
|
-
* `failed` the error that answered the call, if one did. Called
|
|
67
|
-
* after each commit of steps, and before each tool call, with the transcript as the
|
|
68
|
-
* framework stored it: also in an attempt that made no call yet, which would
|
|
69
|
-
* otherwise take one an earlier attempt made, and the model has the result
|
|
70
|
-
* of.
|
|
71
|
-
*/
|
|
72
|
-
export declare function settleCalls(ctx: restate.SessionContext, stored: (id: string, failed?: string) => boolean): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Which of `callIds` made a Restate call that answered, in this invocation
|
|
75
|
-
* or in `invocation`: each with the terminal error it answered with
|
|
76
|
-
* (`Error: <message>`), or `undefined` if it succeeded. A tool call whose
|
|
77
|
-
* call did not answer, or that made none, is left out; so is one whose only
|
|
78
|
-
* answered call is its approval, which it ran (or was denied) after.
|
|
79
|
-
*
|
|
80
|
-
* An earlier `invocation`'s calls are read only while they are still
|
|
81
|
-
* stored, until an invocation of the key makes calls of its own; read,
|
|
82
|
-
* never changed. With `prompt`, the calls of its turn only.
|
|
83
|
-
*/
|
|
84
|
-
export declare function outcomes(ctx: restate.SessionContext, callIds: Iterable<string>, invocation?: string, prompt?: string): Promise<Map<string, string | undefined>>;
|
|
85
|
-
/**
|
|
86
|
-
* Write what rides the next commit ({@link ride}) now, if it is pending: at
|
|
87
|
-
* the end of a turn, when no commit follows that would.
|
|
88
|
-
*/
|
|
89
|
-
export declare const flushCalls: (ctx: restate.SessionContext) => Promise<void>;
|
|
90
|
-
//# sourceMappingURL=calls.d.ts.map
|
package/dist/calls.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAA2B,MAAM,EAAY,MAAM,+BAA+B,CAAC;AA4B1F;;;GAGG;AACH,eAAO,MAAM,MAAM,QAMjB,CAAC;AAQH;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,QACb,OAAO,CAAC,cAAc,SACpB,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,wBAMzC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,iBAE1D;AAoFD;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CASlH;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC1B,GAAG,EAAE,OAAO,CAAC,cAAc,EAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,EAAE,MAAa,EAAE,QAAgB,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO;;IAyBhF;;;;;;;;;;;;;OAaG;sBACqB,MAAM;GAMjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,iBAM9G;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,OAAO,CAAC,cAAc,EAC3B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAc1C;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,OAAO,CAAC,cAAc,kBAAwB,CAAC"}
|
package/dist/calls.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { flushRiders, rideCommit, Schema, ScopeKey } from '@restatedev/sessions/internal';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
/**
|
|
4
|
-
* The table of the {@link Calls}: one row, of the invocation whose calls they are. `answerOnce` applies it with
|
|
5
|
-
* the conversation's, in one commit, as a key's first turn starts.
|
|
6
|
-
*/
|
|
7
|
-
export const SCHEMA = new Schema('restate-agents.calls', [
|
|
8
|
-
`CREATE TABLE restate_agent_calls (
|
|
9
|
-
row INTEGER PRIMARY KEY CHECK (row = 0),
|
|
10
|
-
invocation TEXT NOT NULL,
|
|
11
|
-
calls TEXT NOT NULL
|
|
12
|
-
)`,
|
|
13
|
-
]);
|
|
14
|
-
/** What writes what is held back before anything visible, by holder: the conversation's rows, pi's batch of commits. */
|
|
15
|
-
const HELD = new ScopeKey('what the attempt holds back');
|
|
16
|
-
/**
|
|
17
|
-
* Have {@link flushHeld} write, with `flush`, what a holder keeps back: by
|
|
18
|
-
* default the rows that the conversation of the attempt's turn holds back
|
|
19
|
-
* (`Conversation.hold`), which `answerOnce` sets. A holder of another `slot`
|
|
20
|
-
* (pi's storage, which holds its commits until an effect starts) coexists
|
|
21
|
-
* with it; one of the same slot replaces it, and without a `flush` the slot
|
|
22
|
-
* is released.
|
|
23
|
-
*/
|
|
24
|
-
export const holding = (ctx, flush, slot = 'conversation') => {
|
|
25
|
-
const held = HELD.of(ctx, () => new Map());
|
|
26
|
-
if (flush)
|
|
27
|
-
held.set(slot, flush);
|
|
28
|
-
else
|
|
29
|
-
held.delete(slot);
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Write what the holders keep back, in the order they were set, one after
|
|
33
|
-
* the other: the rows that the conversation of the attempt's turn holds back,
|
|
34
|
-
* if any (see `Conversation.hold`), and pi's batched commits. Call it before
|
|
35
|
-
* what another party sees, or what outlives the attempt: a publish, a
|
|
36
|
-
* Restate call, send or wait. What is held is lost in a crash, and the
|
|
37
|
-
* retried attempt makes it again; what was seen or called must not depend
|
|
38
|
-
* on it.
|
|
39
|
-
*/
|
|
40
|
-
export async function flushHeld(ctx) {
|
|
41
|
-
for (const flush of HELD.get(ctx)?.values() ?? [])
|
|
42
|
-
await flush();
|
|
43
|
-
}
|
|
44
|
-
const UPSERT = 'INSERT OR REPLACE INTO restate_agent_calls (row, invocation, calls) VALUES (0, ?, ?)';
|
|
45
|
-
/** The slot of the calls' write that rides the next commit ({@link ride}). */
|
|
46
|
-
const RIDER = 'restate-agents.calls';
|
|
47
|
-
/**
|
|
48
|
-
* Store `calls`, committed before the call they record is made. The rows the
|
|
49
|
-
* conversation holds back are written first: the call outlives the attempt,
|
|
50
|
-
* and what led to it must too. It is the whole row: what rides the next
|
|
51
|
-
* commit is written, and no longer pending.
|
|
52
|
-
*/
|
|
53
|
-
async function store(ctx, { invocation, calls }) {
|
|
54
|
-
await flushHeld(ctx);
|
|
55
|
-
rideCommit(ctx.db, RIDER, undefined);
|
|
56
|
-
await ctx.db.execute(UPSERT, [invocation, JSON.stringify(calls)]);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Store `state` with the next commit of the database, rather than commit it
|
|
60
|
-
* (see the top of this file), as it is then: a later change replaces it, and
|
|
61
|
-
* the latest state is written. An `urgent` one (an answer) is written on its
|
|
62
|
-
* own unless a commit is under way to write it; one pending that is urgent
|
|
63
|
-
* stays so. A database that cannot ride (a view's) commits it at once.
|
|
64
|
-
*/
|
|
65
|
-
async function ride(ctx, state, urgent = false) {
|
|
66
|
-
const written = rideCommit(ctx.db, RIDER, (tx) => tx.execute(UPSERT, [state.invocation, JSON.stringify(state.calls)]), {
|
|
67
|
-
urgent,
|
|
68
|
-
});
|
|
69
|
-
if (!written)
|
|
70
|
-
await store(ctx, state);
|
|
71
|
-
}
|
|
72
|
-
/** The calls of `invocation`, as stored: none if the row is another invocation's. */
|
|
73
|
-
async function load(ctx, invocation) {
|
|
74
|
-
await SCHEMA.ensure(ctx.db);
|
|
75
|
-
const row = await ctx.db.get('SELECT invocation, calls FROM restate_agent_calls');
|
|
76
|
-
return row?.invocation === invocation
|
|
77
|
-
? { invocation, calls: JSON.parse(row.calls) }
|
|
78
|
-
: { invocation, calls: [] };
|
|
79
|
-
}
|
|
80
|
-
/** Each attempt's id, and its calls, by its context, once they are being read. */
|
|
81
|
-
const ATTEMPT = new ScopeKey('the calls of an attempt');
|
|
82
|
-
/**
|
|
83
|
-
* The attempt of `ctx`: its id, and the calls of its invocation (loaded once,
|
|
84
|
-
* shared by calls made at once). A load that fails (its schema's commit
|
|
85
|
-
* cancelled, say) is not kept: the next asks again, so that a stopped turn's
|
|
86
|
-
* close reads the calls as stored, rather than fail on the load it found.
|
|
87
|
-
*/
|
|
88
|
-
function attemptOf(ctx) {
|
|
89
|
-
const attempt = ATTEMPT.of(ctx, () => ({ id: randomUUID() }));
|
|
90
|
-
if (attempt.calls === undefined) {
|
|
91
|
-
const calls = load(ctx, ctx.request.id);
|
|
92
|
-
attempt.calls = calls;
|
|
93
|
-
calls.catch(() => {
|
|
94
|
-
if (attempt.calls === calls)
|
|
95
|
-
attempt.calls = undefined;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return attempt;
|
|
99
|
-
}
|
|
100
|
-
/** `value` as JSON with its objects' keys sorted: the same input, however its keys came, is the same call. */
|
|
101
|
-
function canonical(value) {
|
|
102
|
-
return JSON.stringify(value, (_key, v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
103
|
-
? Object.fromEntries(Object.entries(v).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
104
|
-
: v);
|
|
105
|
-
}
|
|
106
|
-
/** The prompt whose turn the tools of `ctx` run for, while `answerOnce` answers it. */
|
|
107
|
-
const PROMPT = new ScopeKey('the prompt of the calls');
|
|
108
|
-
/**
|
|
109
|
-
* Run `work` (a turn's) with the calls its tools make kept as prompt
|
|
110
|
-
* `prompt`'s: they are matched, and rejoined, within it only. An invocation
|
|
111
|
-
* that prompts twice, its second prompt making the call its first made
|
|
112
|
-
* (the same tool and input), would otherwise take the first's after a crash
|
|
113
|
-
* (its record not yet forgotten), and never make its own.
|
|
114
|
-
*/
|
|
115
|
-
export async function forPrompt(ctx, prompt, work) {
|
|
116
|
-
const outer = PROMPT.get(ctx);
|
|
117
|
-
PROMPT.set(ctx, prompt);
|
|
118
|
-
try {
|
|
119
|
-
return await work();
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
if (outer === undefined)
|
|
123
|
-
PROMPT.delete(ctx);
|
|
124
|
-
else
|
|
125
|
-
PROMPT.set(ctx, outer);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* The call of tool `tool` with `input` that tool call `callId` makes: the
|
|
130
|
-
* one it made to `tool` before (a run again), or else, if `rejoin`, the one
|
|
131
|
-
* an earlier attempt made with the same tool and input (made again under a
|
|
132
|
-
* new id), or else a new one, an `approval` its tool call waits for if so.
|
|
133
|
-
* `answered()` stores that it answered.
|
|
134
|
-
*/
|
|
135
|
-
export async function callOf(ctx, tool, input, callId, { rejoin = true, approval = false } = {}) {
|
|
136
|
-
const attempt = attemptOf(ctx);
|
|
137
|
-
const state = await attempt.calls;
|
|
138
|
-
const json = canonical(input);
|
|
139
|
-
const prompt = PROMPT.get(ctx);
|
|
140
|
-
const ours = state.calls.filter((c) => c.prompt === prompt);
|
|
141
|
-
// A tool call may make more than one call (an approval, then the tool's
|
|
142
|
-
// own), each to a tool of its own.
|
|
143
|
-
let call = ours.find((c) => c.ids.includes(callId) && c.tool === tool) ??
|
|
144
|
-
(rejoin ? ours.find((c) => c.attempt !== attempt.id && c.tool === tool && c.input === json) : undefined);
|
|
145
|
-
if (call) {
|
|
146
|
-
call.attempt = attempt.id;
|
|
147
|
-
if (!call.ids.includes(callId))
|
|
148
|
-
call.ids.push(callId);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
call = { tool, input: json, ids: [callId], attempt: attempt.id };
|
|
152
|
-
if (approval)
|
|
153
|
-
call.approval = true;
|
|
154
|
-
if (prompt !== undefined)
|
|
155
|
-
call.prompt = prompt;
|
|
156
|
-
state.calls.push(call);
|
|
157
|
-
}
|
|
158
|
-
await store(ctx, state);
|
|
159
|
-
const made = call;
|
|
160
|
-
return {
|
|
161
|
-
id: made.ids[0],
|
|
162
|
-
/**
|
|
163
|
-
* It answered, with `failed` if a terminal error answered it: kept until
|
|
164
|
-
* the transcript has its result.
|
|
165
|
-
*
|
|
166
|
-
* It rides a commit that is under way (the one that stores the call's
|
|
167
|
-
* result, when the framework's write has started), and is otherwise
|
|
168
|
-
* written on its own at once ({@link ride}): a call that answered must
|
|
169
|
-
* not stay unrecorded while something else runs (a slow tool of the same
|
|
170
|
-
* round, a call that waits for a signal). A crash before it is written
|
|
171
|
-
* reads the call as one that did not answer, as a crash just before a
|
|
172
|
-
* commit of its own would have: made again under the same key, and cut off
|
|
173
|
-
* for a stopped turn that another invocation closes ({@link outcomes} reads
|
|
174
|
-
* the stored row; the attempt's own turn reads its state).
|
|
175
|
-
*/
|
|
176
|
-
async answered(failed) {
|
|
177
|
-
made.done = true;
|
|
178
|
-
if (failed !== undefined)
|
|
179
|
-
made.failed = failed;
|
|
180
|
-
await ride(ctx, state, true);
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Forget the calls that answered whose result the framework stored: those
|
|
186
|
-
* of which `stored(id, failed)` is true for the last id they were made with,
|
|
187
|
-
* `failed` the error that answered the call, if one did. Called
|
|
188
|
-
* after each commit of steps, and before each tool call, with the transcript as the
|
|
189
|
-
* framework stored it: also in an attempt that made no call yet, which would
|
|
190
|
-
* otherwise take one an earlier attempt made, and the model has the result
|
|
191
|
-
* of.
|
|
192
|
-
*/
|
|
193
|
-
export async function settleCalls(ctx, stored) {
|
|
194
|
-
const state = await attemptOf(ctx).calls;
|
|
195
|
-
const kept = state.calls.filter((c) => !c.done || !stored(c.ids.at(-1), c.failed));
|
|
196
|
-
if (kept.length === state.calls.length)
|
|
197
|
-
return;
|
|
198
|
-
state.calls = kept;
|
|
199
|
-
await ride(ctx, state);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Which of `callIds` made a Restate call that answered, in this invocation
|
|
203
|
-
* or in `invocation`: each with the terminal error it answered with
|
|
204
|
-
* (`Error: <message>`), or `undefined` if it succeeded. A tool call whose
|
|
205
|
-
* call did not answer, or that made none, is left out; so is one whose only
|
|
206
|
-
* answered call is its approval, which it ran (or was denied) after.
|
|
207
|
-
*
|
|
208
|
-
* An earlier `invocation`'s calls are read only while they are still
|
|
209
|
-
* stored, until an invocation of the key makes calls of its own; read,
|
|
210
|
-
* never changed. With `prompt`, the calls of its turn only.
|
|
211
|
-
*/
|
|
212
|
-
export async function outcomes(ctx, callIds, invocation, prompt) {
|
|
213
|
-
const state = invocation !== undefined && invocation !== ctx.request.id
|
|
214
|
-
? await load(ctx, invocation)
|
|
215
|
-
: await attemptOf(ctx).calls;
|
|
216
|
-
const wanted = new Set(callIds);
|
|
217
|
-
const found = new Map();
|
|
218
|
-
for (const call of state.calls) {
|
|
219
|
-
if (!call.done || call.approval)
|
|
220
|
-
continue;
|
|
221
|
-
// Another prompt's call, of the same invocation: not this turn's.
|
|
222
|
-
if (prompt !== undefined && call.prompt !== undefined && call.prompt !== prompt)
|
|
223
|
-
continue;
|
|
224
|
-
for (const id of call.ids)
|
|
225
|
-
if (wanted.has(id))
|
|
226
|
-
found.set(id, call.failed);
|
|
227
|
-
}
|
|
228
|
-
return found;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Write what rides the next commit ({@link ride}) now, if it is pending: at
|
|
232
|
-
* the end of a turn, when no commit follows that would.
|
|
233
|
-
*/
|
|
234
|
-
export const flushCalls = (ctx) => flushRiders(ctx.db);
|
|
235
|
-
//# sourceMappingURL=calls.js.map
|
package/dist/calls.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAwCA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA2BzC;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,EAAE;IACvD;;;;IAIE;CACH,CAAC,CAAC;AAKH,wHAAwH;AACxH,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAmC,6BAA6B,CAAC,CAAC;AAE3F;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,GAA2B,EAC3B,KAAwC,EACxC,IAAI,GAAG,cAAc,EACrB,EAAE;IACF,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3C,IAAI,KAAK;QAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;;QAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;A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AAE,UAAU,CAAC;QAC7B,CAAC,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IACpD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ;YAAE,SAAS;QAC1C,kEAAkE;QAClE,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM;YAAE,SAAS;QAC1F,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,GAAG;YAAE,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAA2B,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC"}
|
package/dist/claude/index.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import * as restate from '@restatedev/sessions';
|
|
2
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
3
|
-
import type { BetaRunnableTool, BetaToolRunContext } from '@anthropic-ai/sdk/lib/tools/BetaRunnableTool';
|
|
4
|
-
import { type Configure, type Summarize } from '../common.ts';
|
|
5
|
-
import { type Items } from '../conversation.ts';
|
|
6
|
-
import { type Answer } from '../output.ts';
|
|
7
|
-
import type { z } from 'zod';
|
|
8
|
-
import { type Definition } from '../object.ts';
|
|
9
|
-
import { type Tool as AnyTool } from '../tools.ts';
|
|
10
|
-
type MessageParam = Anthropic.Beta.Messages.BetaMessageParam;
|
|
11
|
-
/** The id of the tool call a tool runs for: the runner always passes it. */
|
|
12
|
-
export declare const callId: (context?: BetaToolRunContext) => string;
|
|
13
|
-
/**
|
|
14
|
-
* Claude's items: the SDK's messages, as JSON. A user's text is said by the
|
|
15
|
-
* user, an assistant's by the assistant, and its `tool_use` blocks are its
|
|
16
|
-
* calls; a `tool_result` is a result. A server tool's blocks (and a
|
|
17
|
-
* `system` message) say nothing: they leave no open call the API would
|
|
18
|
-
* refuse a result for.
|
|
19
|
-
*/
|
|
20
|
-
export declare const items: Items<MessageParam>;
|
|
21
|
-
/** How much effort the model puts into a reply (Anthropic's `output_config.effort`). */
|
|
22
|
-
export type Effort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
23
|
-
/** An agent's options: `chat` and `prompt` take them. */
|
|
24
|
-
export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
|
|
25
|
-
/** The model, as `anthropic/model-id`: MODEL, or else anthropic/claude-sonnet-5-5. */
|
|
26
|
-
model?: string;
|
|
27
|
-
/** The system prompt. */
|
|
28
|
-
system?: string;
|
|
29
|
-
/** The agent's tools: `tool()`s, Restate's (`call`, `signal`...), or the SDK's (such as `betaZodTool`s). */
|
|
30
|
-
tools?: (AnyTool | BetaRunnableTool)[];
|
|
31
|
-
/** The client of the Anthropic API: by default one with ANTHROPIC_API_KEY. */
|
|
32
|
-
client?: Anthropic;
|
|
33
|
-
/**
|
|
34
|
-
* The most tokens of each of the model's replies (default 16000). A reply
|
|
35
|
-
* cut off there ends its prompt, which fails (a terminal error).
|
|
36
|
-
*/
|
|
37
|
-
maxTokens?: number;
|
|
38
|
-
/** How much effort the model puts into each reply: more is more thorough, and slower (default: the model's). */
|
|
39
|
-
effort?: Effort;
|
|
40
|
-
/**
|
|
41
|
-
* The answer as data: a zod object, whose JSON the agent replies with
|
|
42
|
-
* (checked), and `chat` and `prompt` answer with (see output.ts).
|
|
43
|
-
*/
|
|
44
|
-
output?: O;
|
|
45
|
-
/**
|
|
46
|
-
* Whether the model is asked for `output` natively, with the API's
|
|
47
|
-
* structured outputs (`output_config.format`: the JSON schema the API
|
|
48
|
-
* holds the final reply to), rather than in the prompt (default: if the
|
|
49
|
-
* model has them, as Claude's have since the 4.5 models). A schema the API
|
|
50
|
-
* cannot take (too complex, say) refuses the message: `false` asks in the
|
|
51
|
-
* prompt instead.
|
|
52
|
-
*/
|
|
53
|
-
nativeOutput?: boolean;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
|
|
57
|
-
* of an invocation is a prompt of its own.
|
|
58
|
-
* With `output`, it answers with the value the agent replies with (see
|
|
59
|
-
* output.ts), not its text: a reply that is not one is asked again within
|
|
60
|
-
* its turn, once. A model with structured outputs is asked for it natively
|
|
61
|
-
* (`nativeOutput`), else in the prompt.
|
|
62
|
-
*/
|
|
63
|
-
export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
|
|
64
|
-
/**
|
|
65
|
-
* A chat handler: each message an invocation, the conversation in the
|
|
66
|
-
* object's database, with `options`, or the options a function of the
|
|
67
|
-
* invocation's context gives. It takes the message as plain text
|
|
68
|
-
* (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
|
|
69
|
-
*/
|
|
70
|
-
export declare const chat: <O extends z.ZodObject | undefined = undefined>(options?: Configure<Options<O>>) => {
|
|
71
|
-
input: restate.Serde<string>;
|
|
72
|
-
accept: string;
|
|
73
|
-
explicitCancellation: boolean;
|
|
74
|
-
handler: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* A view of the conversation as clients read it: a page at a time, or what
|
|
78
|
-
* is new or changed since a cursor; `view: 'summary'` for each turn's
|
|
79
|
-
* message and answer. It answers while a message is answered.
|
|
80
|
-
*/
|
|
81
|
-
export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
82
|
-
/**
|
|
83
|
-
* How an agent of `options` summarizes the earliest turns, past its budget:
|
|
84
|
-
* with its own client and model (`agent()` gives it; for an object of your
|
|
85
|
-
* own, `sessionObject`'s `summarize`).
|
|
86
|
-
*/
|
|
87
|
-
export declare const summarizer: (options?: Options) => Summarize;
|
|
88
|
-
/** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
|
|
89
|
-
export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, window, budget, summarize, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
|
|
90
|
-
signal: (ctx: import("../common.ts").AgentViewContext, signal: import("../companion.ts").Signal) => Promise<import("../companion.ts").Resolved>;
|
|
91
|
-
pending: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Waiting[]>;
|
|
92
|
-
status: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Status>;
|
|
93
|
-
stop: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
94
|
-
notifications: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Notifications>;
|
|
95
|
-
watch: (ctx: import("../common.ts").AgentViewContext, watch: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
|
|
96
|
-
} & {
|
|
97
|
-
clear: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
98
|
-
steer: (ctx: import("../common.ts").AgentViewContext, text: string) => Promise<import("../companion.ts").Steered>;
|
|
99
|
-
sync: (ctx: import("../common.ts").AgentViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
|
|
100
|
-
} & {
|
|
101
|
-
chat: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
102
|
-
} & {
|
|
103
|
-
messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
104
|
-
}>;
|
|
105
|
-
export {};
|
|
106
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAEzG,OAAO,EAGL,KAAK,SAAS,EASd,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAc,KAAK,KAAK,EAAyB,MAAM,oBAAoB,CAAC;AAGnF,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAwB,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAEzE,KAAK,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;AAE7D,4EAA4E;AAC5E,eAAO,MAAM,MAAM,aAAc,kBAAkB,WAGlD,CAAC;AAoBF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,YAAY,CAkDrC,CAAC;AA4LF,wFAAwF;AACxF,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAEjE,yDAAyD;AACzD,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,CAAC,CAAC,SAAS,GAAG,SA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