@genesislcap/ai-assistant 15.58.1 → 15.59.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/dist/ai-assistant.api.json +10096 -6986
- package/dist/ai-assistant.d.ts +545 -101
- package/dist/chat-driver.cjs +624 -207
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +624 -207
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +1836 -378
- package/dist/dts/components/agent-session/agent-session.d.ts +19 -3
- package/dist/dts/components/agent-session/agent-session.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/ai-driver.d.ts +120 -10
- package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/base-driver-decorator.d.ts +103 -0
- package/dist/dts/components/ai-driver/base-driver-decorator.d.ts.map +1 -0
- package/dist/dts/components/ai-driver/index.d.ts +3 -1
- package/dist/dts/components/ai-driver/index.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +84 -8
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/interaction-controller.d.ts +37 -3
- package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +30 -93
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -1
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +4 -4
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/state/debug-event-log.d.ts +1 -1
- package/dist/dts/state/debug-event-log.d.ts.map +1 -1
- package/dist/dts/state/interaction-context.d.ts +7 -1
- package/dist/dts/state/interaction-context.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/dts/suggestions/generate-suggestions.d.ts.map +1 -1
- package/dist/dts/types/handler-capability.d.ts +28 -0
- package/dist/dts/types/handler-capability.d.ts.map +1 -0
- package/dist/dts/types/interaction-context.d.ts +16 -0
- package/dist/dts/types/interaction-context.d.ts.map +1 -1
- package/dist/dts/types/interaction-interceptor.d.ts +109 -0
- package/dist/dts/types/interaction-interceptor.d.ts.map +1 -0
- package/dist/dts/utils/delegated-message.d.ts +52 -0
- package/dist/dts/utils/delegated-message.d.ts.map +1 -0
- package/dist/dts/utils/history-transform.d.ts.map +1 -1
- package/dist/esm/components/agent-session/agent-session.js +17 -0
- package/dist/esm/components/ai-driver/ai-driver.js +21 -1
- package/dist/esm/components/ai-driver/base-driver-decorator.js +211 -0
- package/dist/esm/components/ai-driver/index.js +2 -1
- package/dist/esm/components/chat-driver/chat-driver.js +195 -14
- package/dist/esm/components/chat-driver/interaction-controller.js +168 -14
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +72 -196
- package/dist/esm/index.js +1 -0
- package/dist/esm/main/main.js +79 -77
- package/dist/esm/state/debug-event-log.js +7 -2
- package/dist/esm/state/interaction-context.js +11 -0
- package/dist/esm/state/persistence/session-persister.js +5 -6
- package/dist/esm/suggestions/generate-suggestions.js +8 -1
- package/dist/esm/types/handler-capability.js +1 -0
- package/dist/esm/types/interaction-interceptor.js +1 -0
- package/dist/esm/utils/delegated-message.js +25 -0
- package/dist/esm/utils/history-transform.js +12 -1
- package/package.json +17 -17
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { InteractionContext } from './interaction-context';
|
|
2
|
+
/**
|
|
3
|
+
* The handle an interceptor uses to move a pending interaction between the person and itself
|
|
4
|
+
* (GENC-1660): to the person when it hands back or is paused, back to itself when resumed.
|
|
5
|
+
*
|
|
6
|
+
* Every interceptor is offered one, but only the claimant's works: on any other interceptor's
|
|
7
|
+
* handle, and after the interaction ends, its members do nothing and return `false`. A claim is
|
|
8
|
+
* granted only once `onInteractionOpened` has returned `'claim'` (it may yet be refused), so the
|
|
9
|
+
* claimant's own handle does nothing until then either: act on it afterwards. Views read the
|
|
10
|
+
* result as `ctx.heldBy`; they never change it.
|
|
11
|
+
*
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
export interface InteractionHold {
|
|
15
|
+
/**
|
|
16
|
+
* Give the interaction to the person (`'user'`) or back to the claimant (`'claimant'`). Notifies
|
|
17
|
+
* the context's subscribers and records `interaction.held`. Returns whether it applied.
|
|
18
|
+
*/
|
|
19
|
+
set(holder: 'user' | 'claimant'): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Say what the claimant decided, before it settles the interaction, so the tool that asked is
|
|
22
|
+
* told honestly (GENC-1660). When the interaction then resolves while the claimant holds it, the
|
|
23
|
+
* driver adds a {@link DelegatedDecision} built from this to that tool's result, so the working
|
|
24
|
+
* agent learns the choice was made on the user's behalf and what the user was shown about it.
|
|
25
|
+
*
|
|
26
|
+
* Optional to call: without it the record carries only the framing. Later calls replace earlier
|
|
27
|
+
* ones. Returns `false`, recording nothing, unless this interceptor holds the interaction.
|
|
28
|
+
*/
|
|
29
|
+
recordDecision(decision: {
|
|
30
|
+
choice?: string;
|
|
31
|
+
shownToUser?: string;
|
|
32
|
+
}): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Settle the interaction AS the claimant (GENC-1660). The only route that stamps the claimant as
|
|
35
|
+
* `answeredBy`: an answer through the host's `resolveInteraction` — a click — is the person's,
|
|
36
|
+
* whoever held the interaction at the time, so attribution never depends on a view honouring
|
|
37
|
+
* `heldBy`. Returns `false`, settling nothing, unless this interceptor holds it right now.
|
|
38
|
+
*/
|
|
39
|
+
resolve(result: unknown): boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What the working agent is told about an interaction an interceptor answered (GENC-1660): added
|
|
43
|
+
* to the result of the tool call that requested it, as `decidedOnUsersBehalf` on an object result
|
|
44
|
+
* or as a line appended to a text one.
|
|
45
|
+
*
|
|
46
|
+
* Built only from what the platform already holds — the claimant's framing, and the choice and
|
|
47
|
+
* narration it recorded — so the text the person saw and the text the agent is told about are the
|
|
48
|
+
* same string. It never names the claimant, so the agent has nothing to repeat about one.
|
|
49
|
+
*
|
|
50
|
+
* @beta
|
|
51
|
+
*/
|
|
52
|
+
export interface DelegatedDecision {
|
|
53
|
+
/** The claimant's {@link InteractionInterceptor.decisionFraming}, e.g. "Decided on the user's behalf". */
|
|
54
|
+
readonly framing: string;
|
|
55
|
+
/** What was chosen, as recorded by the claimant. */
|
|
56
|
+
readonly choice?: string;
|
|
57
|
+
/** What the person was shown about it, verbatim, as the assistant's own words. */
|
|
58
|
+
readonly shownToUser?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A new interaction, as offered to each installed interceptor (GENC-1660).
|
|
62
|
+
*
|
|
63
|
+
* Offered once, at the root driver, after its context exists and before its message is appended,
|
|
64
|
+
* so the first render of its widget already knows who holds it.
|
|
65
|
+
*
|
|
66
|
+
* @beta
|
|
67
|
+
*/
|
|
68
|
+
export interface InteractionOpened {
|
|
69
|
+
readonly interactionId: string;
|
|
70
|
+
readonly componentName: string;
|
|
71
|
+
/** The `data` the widget was requested with. */
|
|
72
|
+
readonly data: unknown;
|
|
73
|
+
/**
|
|
74
|
+
* The agents that asked for it, outermost first: the root's active agent, then each sub-agent
|
|
75
|
+
* the request travelled up through — e.g. `['bootstrap', 'brief-critic']`. The last entry is the
|
|
76
|
+
* agent whose tool handler called `requestInteraction`.
|
|
77
|
+
*/
|
|
78
|
+
readonly ownerPath: readonly string[];
|
|
79
|
+
/** Set from `InteractionRequestOptions.userOnly`: nobody may claim it. */
|
|
80
|
+
readonly userOnly: boolean;
|
|
81
|
+
/** The interaction's live context, the same object its widget is handed. */
|
|
82
|
+
readonly ctx: InteractionContext;
|
|
83
|
+
/** See {@link InteractionHold}. Works only for the interceptor whose claim was granted. */
|
|
84
|
+
readonly hold: InteractionHold;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Something that is told about every interaction a driver opens, and may answer it instead of the
|
|
88
|
+
* person (GENC-1660). Installed with `AiDriver.addInteractionInterceptor`, typically by a driver
|
|
89
|
+
* decorator such as an autopilot or a test harness.
|
|
90
|
+
*
|
|
91
|
+
* Interceptors are asked outermost first. The first to claim an interaction holds it; the rest
|
|
92
|
+
* observe — they see the same context but their `hold` does nothing. Nobody can claim a `userOnly`
|
|
93
|
+
* interaction. A throwing interceptor is logged and treated as abstaining.
|
|
94
|
+
*
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
export interface InteractionInterceptor {
|
|
98
|
+
/** The holder id this interceptor's claims are recorded under, e.g. `'autopilot'`. Not `'user'`. */
|
|
99
|
+
readonly id: string;
|
|
100
|
+
/**
|
|
101
|
+
* How a {@link DelegatedDecision} it settled opens, as the working agent reads it. Must not name
|
|
102
|
+
* the interceptor. Defaults to "Decided on the user's behalf"; an autopilot grounded in a brief
|
|
103
|
+
* would say "Decided on the user's behalf, from their brief".
|
|
104
|
+
*/
|
|
105
|
+
readonly decisionFraming?: string;
|
|
106
|
+
/** Return `'claim'` to hold the interaction, or nothing to leave it with the person. */
|
|
107
|
+
onInteractionOpened(opened: InteractionOpened): 'claim' | undefined | void;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=interaction-interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction-interceptor.d.ts","sourceRoot":"","sources":["../../../src/types/interaction-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAC1C;;;;;;;;OAQG;IACH,cAAc,CAAC,QAAQ,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;IAC7E;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAChC,0GAA0G;IAC1G,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAAC;IACjC,2FAA2F;IAC3F,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,sBAAsB;IACrC,oGAAoG;IACpG,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,wFAAwF;IACxF,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;CAC5E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ChatMessage } from '@genesislcap/foundation-ai';
|
|
2
|
+
/**
|
|
3
|
+
* A message written or sent on the user's behalf by a driver decorator (GENC-1660). See
|
|
4
|
+
* `ChatMessage.delegate`.
|
|
5
|
+
*
|
|
6
|
+
* @beta
|
|
7
|
+
*/
|
|
8
|
+
export type DelegatedMessage = ChatMessage & {
|
|
9
|
+
delegate: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Whether `message` was written or sent on the user's behalf. A delegated message renders as the
|
|
13
|
+
* assistant, whatever its role.
|
|
14
|
+
*
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
export declare const isDelegated: (message: ChatMessage) => message is DelegatedMessage;
|
|
18
|
+
/**
|
|
19
|
+
* How a delegated `user` message is framed for the model when its sender gives no phrase. Names no
|
|
20
|
+
* decorator, so the model has none to repeat.
|
|
21
|
+
*
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_DELEGATE_FRAMING = "Sent on the user's behalf.";
|
|
25
|
+
/**
|
|
26
|
+
* Options for `AiDriver.sendMessage` (GENC-1660).
|
|
27
|
+
*
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
export interface SendMessageOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Send the message on the user's behalf, as this decorator (e.g. `'autopilot'`). The platform
|
|
33
|
+
* stamps it on the stored message as `delegate`, so it renders as the assistant and the model
|
|
34
|
+
* reads it framed.
|
|
35
|
+
*/
|
|
36
|
+
delegate?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The phrase the model reads in front of a delegated message. Defaults to
|
|
39
|
+
* {@link DEFAULT_DELEGATE_FRAMING}. Ignored unless `delegate` is set.
|
|
40
|
+
*/
|
|
41
|
+
delegateFraming?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A delegated `user` message's content as the model reads it: its framing in brackets, then the
|
|
45
|
+
* text. The one place this string is built, so the first model call (which takes the message as
|
|
46
|
+
* its input) and every later call (which reads it from history) send the same bytes and the cache
|
|
47
|
+
* prefix holds.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function frameDelegatedContent(content: string, framing: string | undefined): string;
|
|
52
|
+
//# sourceMappingURL=delegated-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegated-message.d.ts","sourceRoot":"","sources":["../../../src/utils/delegated-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,WAAW,KAAG,OAAO,IAAI,gBAC1C,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,+BAA+B,CAAC;AAErE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history-transform.d.ts","sourceRoot":"","sources":["../../../src/utils/history-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAEL,KAAK,oBAAoB,EAI1B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"history-transform.d.ts","sourceRoot":"","sources":["../../../src/utils/history-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAEL,KAAK,oBAAoB,EAI1B,MAAM,kBAAkB,CAAC;AAqC1B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,EAAE,CAsBjG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,EAAE,CAG3F;AAID;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CASvF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,eAAe,GAAE,MAAkC,EACnD,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,GAAG,IAAI,CAkBf;AAED,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,GAAG,IAAI,CAc7B;AAqCD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,SAAS,WAAW,EAAE,GAAG;IAC/E,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAkBA;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,EAAE,CAkBnF;AAED,oEAAoE;AACpE,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAG7D"}
|
|
@@ -150,6 +150,8 @@ export class AgentSession {
|
|
|
150
150
|
transition.flowOwnerChangedTo = agent.name;
|
|
151
151
|
}
|
|
152
152
|
this.active = agent;
|
|
153
|
+
if (switched)
|
|
154
|
+
this.reportTransition(transition);
|
|
153
155
|
return transition;
|
|
154
156
|
});
|
|
155
157
|
}
|
|
@@ -174,9 +176,24 @@ export class AgentSession {
|
|
|
174
176
|
this.flowOwner = null;
|
|
175
177
|
transition.flowOwnerChangedTo = null;
|
|
176
178
|
}
|
|
179
|
+
this.reportTransition(transition);
|
|
177
180
|
return transition;
|
|
178
181
|
});
|
|
179
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Hand a transition to the owner. A throwing listener is logged rather than propagated, for the
|
|
185
|
+
* same reason a throwing hook is: the transition has already happened, and failing the caller
|
|
186
|
+
* would leave it believing it had not.
|
|
187
|
+
*/
|
|
188
|
+
reportTransition(transition) {
|
|
189
|
+
var _a, _b;
|
|
190
|
+
try {
|
|
191
|
+
(_b = (_a = this.deps).onTransition) === null || _b === void 0 ? void 0 : _b.call(_a, transition);
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
logger.warn(`${WARN_PREFIX}: onTransition threw:`, e);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
180
197
|
/**
|
|
181
198
|
* Fire `onDeactivate` on the active agent and abort pending lifecycle work, for session
|
|
182
199
|
* teardown, so machines release resources cleanly. The session is not reusable afterwards: the
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The event types in {@link AiDriverEventMap}, as a runtime list. Built from a record keyed by the
|
|
3
|
+
* map, so adding an event to the map without adding it here is a compile error.
|
|
4
|
+
*
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export const AI_DRIVER_EVENT_TYPES = Object.keys({
|
|
8
|
+
'history-updated': true,
|
|
9
|
+
'sub-agent-history-updated': true,
|
|
10
|
+
'sub-agent-start': true,
|
|
11
|
+
'sub-agent-stop': true,
|
|
12
|
+
'interaction-start': true,
|
|
13
|
+
'interaction-stop': true,
|
|
14
|
+
'provider-changed': true,
|
|
15
|
+
'external-cost-recorded': true,
|
|
16
|
+
'agent-changed': true,
|
|
17
|
+
'agent-released': true,
|
|
18
|
+
'flow-owner-changed': true,
|
|
19
|
+
'orchestrating-start': true,
|
|
20
|
+
'orchestrating-stop': true,
|
|
21
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { AI_DRIVER_EVENT_TYPES, } from './ai-driver';
|
|
2
|
+
/**
|
|
3
|
+
* The base of every driver decorator (GENC-1660): an {@link AiDriver} that wraps another and
|
|
4
|
+
* passes every member, and every event in {@link AiDriverEventMap}, through to it.
|
|
5
|
+
*
|
|
6
|
+
* A decorator extends this and overrides only what it changes, so decorators stack in any order
|
|
7
|
+
* and a member or event added to `AiDriver` reaches the host through every layer by default.
|
|
8
|
+
* `OrchestratingDriver` is one; it used to forward by hand, and twice a member it did not forward
|
|
9
|
+
* silently did nothing for every multi-agent host (`recordExternalCost`, then
|
|
10
|
+
* `getHistoryForPersistence`).
|
|
11
|
+
*
|
|
12
|
+
* Abstract with no abstract members, so it cannot be constructed on its own: a decorator that
|
|
13
|
+
* changes nothing is not one.
|
|
14
|
+
*
|
|
15
|
+
* Optional `AiDriver` members are implemented here unconditionally, as a forward that falls back
|
|
16
|
+
* to the "not supported" answer when the inner driver lacks them. A host that feature-detects with
|
|
17
|
+
* `?.` therefore always finds them, and gets the same answer it would from the inner driver.
|
|
18
|
+
*
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
export class BaseDriverDecorator extends EventTarget {
|
|
22
|
+
constructor(inner) {
|
|
23
|
+
super();
|
|
24
|
+
this.inner = inner;
|
|
25
|
+
/** Undoes this layer's hold on its inner driver; see {@link BaseDriverDecorator.detach}. */
|
|
26
|
+
this.detachers = [];
|
|
27
|
+
// Re-dispatch, not re-target: an event belongs to one target, so each layer raises its own
|
|
28
|
+
// copy with the same detail, as the orchestrator always did.
|
|
29
|
+
for (const type of AI_DRIVER_EVENT_TYPES) {
|
|
30
|
+
const forward = (e) => {
|
|
31
|
+
this.dispatchEvent(new CustomEvent(type, { detail: e.detail }));
|
|
32
|
+
};
|
|
33
|
+
inner.addEventListener(type, forward);
|
|
34
|
+
this.onDetach(() => inner.removeEventListener(type, forward));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Let go of the inner driver WITHOUT disposing it: stop forwarding its events, and undo whatever
|
|
39
|
+
* a subclass registered through {@link BaseDriverDecorator.onDetach} (its interceptors, its
|
|
40
|
+
* capabilities, its own listeners). For dropping or replacing a decorator while the driver it
|
|
41
|
+
* wrapped lives on — otherwise the old layer keeps re-dispatching every event and is never
|
|
42
|
+
* collected. Idempotent. `dispose()` detaches too.
|
|
43
|
+
*/
|
|
44
|
+
detach() {
|
|
45
|
+
for (const undo of this.detachers.splice(0)) {
|
|
46
|
+
try {
|
|
47
|
+
undo();
|
|
48
|
+
}
|
|
49
|
+
catch (_a) {
|
|
50
|
+
// One failed undo must not keep the rest attached.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Register something {@link BaseDriverDecorator.detach} must undo. */
|
|
55
|
+
onDetach(undo) {
|
|
56
|
+
this.detachers.push(undo);
|
|
57
|
+
}
|
|
58
|
+
sendMessage(input, attachments, options) {
|
|
59
|
+
return this.inner.sendMessage(input, attachments, options);
|
|
60
|
+
}
|
|
61
|
+
continueFromHistory(transientPrimer, options) {
|
|
62
|
+
return this.inner.continueFromHistory(transientPrimer, options);
|
|
63
|
+
}
|
|
64
|
+
resolveInteraction(interactionId, result) {
|
|
65
|
+
this.inner.resolveInteraction(interactionId, result);
|
|
66
|
+
}
|
|
67
|
+
recordExternalCost(interactionId, costUsd) {
|
|
68
|
+
var _a, _b, _c;
|
|
69
|
+
return (_c = (_b = (_a = this.inner).recordExternalCost) === null || _b === void 0 ? void 0 : _b.call(_a, interactionId, costUsd)) !== null && _c !== void 0 ? _c : false;
|
|
70
|
+
}
|
|
71
|
+
getInteractionContext(interactionId) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
return (_b = (_a = this.inner).getInteractionContext) === null || _b === void 0 ? void 0 : _b.call(_a, interactionId);
|
|
74
|
+
}
|
|
75
|
+
loadHistory(messages) {
|
|
76
|
+
this.inner.loadHistory(messages);
|
|
77
|
+
}
|
|
78
|
+
primeRestoredAgentState(snapshots) {
|
|
79
|
+
this.inner.primeRestoredAgentState(snapshots);
|
|
80
|
+
}
|
|
81
|
+
canRestoreFlowOwner(agentName) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
return (_c = (_b = (_a = this.inner).canRestoreFlowOwner) === null || _b === void 0 ? void 0 : _b.call(_a, agentName)) !== null && _c !== void 0 ? _c : false;
|
|
84
|
+
}
|
|
85
|
+
canResumeRestoredFlow(agentName) {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
return (_c = (_b = (_a = this.inner).canResumeRestoredFlow) === null || _b === void 0 ? void 0 : _b.call(_a, agentName)) !== null && _c !== void 0 ? _c : false;
|
|
88
|
+
}
|
|
89
|
+
resumeRestoredFlow(resumeNote, agent) {
|
|
90
|
+
var _a, _b, _c;
|
|
91
|
+
return (_c = (_b = (_a = this.inner).resumeRestoredFlow) === null || _b === void 0 ? void 0 : _b.call(_a, resumeNote, agent)) !== null && _c !== void 0 ? _c : Promise.resolve(undefined);
|
|
92
|
+
}
|
|
93
|
+
getRawHistory() {
|
|
94
|
+
var _a, _b, _c;
|
|
95
|
+
return (_c = (_b = (_a = this.inner).getRawHistory) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
96
|
+
}
|
|
97
|
+
getHistoryForPersistence() {
|
|
98
|
+
var _a, _b, _c;
|
|
99
|
+
return (_c = (_b = (_a = this.inner).getHistoryForPersistence) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [...this.getRawHistory()];
|
|
100
|
+
}
|
|
101
|
+
getCondensePoliciesForPersistence(messages) {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
return (_c = (_b = (_a = this.inner).getCondensePoliciesForPersistence) === null || _b === void 0 ? void 0 : _b.call(_a, messages)) !== null && _c !== void 0 ? _c : [];
|
|
104
|
+
}
|
|
105
|
+
restoreCondensePolicies(entries) {
|
|
106
|
+
var _a, _b, _c;
|
|
107
|
+
return ((_c = (_b = (_a = this.inner).restoreCondensePolicies) === null || _b === void 0 ? void 0 : _b.call(_a, entries)) !== null && _c !== void 0 ? _c : { restored: 0, awaitingReactivation: 0 });
|
|
108
|
+
}
|
|
109
|
+
getActiveAgent() {
|
|
110
|
+
return this.inner.getActiveAgent();
|
|
111
|
+
}
|
|
112
|
+
setPinnedAgent(name) {
|
|
113
|
+
this.inner.setPinnedAgent(name);
|
|
114
|
+
}
|
|
115
|
+
setFlowOwner(name) {
|
|
116
|
+
this.inner.setFlowOwner(name);
|
|
117
|
+
}
|
|
118
|
+
getFlowOwner() {
|
|
119
|
+
var _a, _b, _c;
|
|
120
|
+
return (_c = (_b = (_a = this.inner).getFlowOwner) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Forwarded, so an interceptor installed on any layer lands on the driver that opens the
|
|
124
|
+
* interactions. A decorator that answers interactions installs its own on `this.inner`.
|
|
125
|
+
*/
|
|
126
|
+
addInteractionInterceptor(interceptor) {
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
return (_c = (_b = (_a = this.inner).addInteractionInterceptor) === null || _b === void 0 ? void 0 : _b.call(_a, interceptor)) !== null && _c !== void 0 ? _c : (() => undefined);
|
|
129
|
+
}
|
|
130
|
+
presentInteraction(componentName, data, options) {
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
return ((_c = (_b = (_a = this.inner).presentInteraction) === null || _b === void 0 ? void 0 : _b.call(_a, componentName, data, options)) !== null && _c !== void 0 ? _c : Promise.reject(new Error('presentInteraction: the inner driver cannot show interactions.')));
|
|
133
|
+
}
|
|
134
|
+
provideHandlerCapability(name, factory) {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
return (_c = (_b = (_a = this.inner).provideHandlerCapability) === null || _b === void 0 ? void 0 : _b.call(_a, name, factory)) !== null && _c !== void 0 ? _c : (() => undefined);
|
|
137
|
+
}
|
|
138
|
+
getContextReserve() {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
return (_b = (_a = this.inner).getContextReserve) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
141
|
+
}
|
|
142
|
+
getPreambleTokens() {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
return (_b = (_a = this.inner).getPreambleTokens) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
145
|
+
}
|
|
146
|
+
setContextGuard(policy) {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
(_b = (_a = this.inner).setContextGuard) === null || _b === void 0 ? void 0 : _b.call(_a, policy);
|
|
149
|
+
}
|
|
150
|
+
compact(options) {
|
|
151
|
+
var _a, _b, _c;
|
|
152
|
+
return (_c = (_b = (_a = this.inner).compact) === null || _b === void 0 ? void 0 : _b.call(_a, options)) !== null && _c !== void 0 ? _c : Promise.resolve(null);
|
|
153
|
+
}
|
|
154
|
+
getCompactionPlan(options) {
|
|
155
|
+
var _a, _b, _c;
|
|
156
|
+
return (_c = (_b = (_a = this.inner).getCompactionPlan) === null || _b === void 0 ? void 0 : _b.call(_a, options)) !== null && _c !== void 0 ? _c : null;
|
|
157
|
+
}
|
|
158
|
+
canCompact(options) {
|
|
159
|
+
var _a, _b, _c;
|
|
160
|
+
return (_c = (_b = (_a = this.inner).canCompact) === null || _b === void 0 ? void 0 : _b.call(_a, options)) !== null && _c !== void 0 ? _c : false;
|
|
161
|
+
}
|
|
162
|
+
isBusy() {
|
|
163
|
+
return this.inner.isBusy();
|
|
164
|
+
}
|
|
165
|
+
getSuggestions(history, prompt, count, allAgentInfo) {
|
|
166
|
+
return this.inner.getSuggestions(history, prompt, count, allAgentInfo);
|
|
167
|
+
}
|
|
168
|
+
getTurnSnapshots() {
|
|
169
|
+
var _a, _b, _c;
|
|
170
|
+
return (_c = (_b = (_a = this.inner).getTurnSnapshots) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The inner driver's entries. Diagnostics compose down the stack: a decorator with entries of
|
|
174
|
+
* its own overrides this and appends them to `super.getExternalDiagnostics()`.
|
|
175
|
+
*/
|
|
176
|
+
getExternalDiagnostics() {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
return (_c = (_b = (_a = this.inner).getExternalDiagnostics) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
179
|
+
}
|
|
180
|
+
getActiveProviderName() {
|
|
181
|
+
return this.inner.getActiveProviderName();
|
|
182
|
+
}
|
|
183
|
+
dispose() {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
const disposed = (_b = (_a = this.inner).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
186
|
+
this.detach();
|
|
187
|
+
return disposed;
|
|
188
|
+
}
|
|
189
|
+
cancel() {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
(_b = (_a = this.inner).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Every driver in the stack, outermost first: `driver`, then each inner driver down to the one
|
|
195
|
+
* that is not a decorator.
|
|
196
|
+
*
|
|
197
|
+
* For diagnostics and labelling only: behaviour must go through `AiDriver` members, which every
|
|
198
|
+
* layer forwards, never through a concrete class found here.
|
|
199
|
+
*
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
static layers(driver) {
|
|
203
|
+
const layers = [driver];
|
|
204
|
+
let current = driver;
|
|
205
|
+
while (current instanceof BaseDriverDecorator) {
|
|
206
|
+
current = current.inner;
|
|
207
|
+
layers.push(current);
|
|
208
|
+
}
|
|
209
|
+
return layers;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { AI_DRIVER_EVENT_TYPES } from './ai-driver';
|
|
2
|
+
export { BaseDriverDecorator } from './base-driver-decorator';
|