@memberjunction/ai 6.1.0-edge.6 → 6.1.0-edge.7

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.
Files changed (37) hide show
  1. package/dist/generic/baseLLM.d.ts +14 -0
  2. package/dist/generic/baseLLM.d.ts.map +1 -1
  3. package/dist/generic/baseLLM.js +40 -3
  4. package/dist/generic/baseLLM.js.map +1 -1
  5. package/dist/generic/baseRealtime.d.ts +110 -7
  6. package/dist/generic/baseRealtime.d.ts.map +1 -1
  7. package/dist/generic/baseRealtime.js +17 -7
  8. package/dist/generic/baseRealtime.js.map +1 -1
  9. package/dist/generic/chat.types.d.ts +202 -2
  10. package/dist/generic/chat.types.d.ts.map +1 -1
  11. package/dist/generic/chat.types.js +114 -1
  12. package/dist/generic/chat.types.js.map +1 -1
  13. package/dist/generic/modelConfiguration.d.ts +146 -31
  14. package/dist/generic/modelConfiguration.d.ts.map +1 -1
  15. package/dist/generic/modelConfiguration.js +22 -11
  16. package/dist/generic/modelConfiguration.js.map +1 -1
  17. package/dist/generic/openAICompatibleTools.d.ts +129 -0
  18. package/dist/generic/openAICompatibleTools.d.ts.map +1 -0
  19. package/dist/generic/openAICompatibleTools.js +94 -0
  20. package/dist/generic/openAICompatibleTools.js.map +1 -0
  21. package/dist/generic/realtimeProxyRegistry.d.ts +19 -0
  22. package/dist/generic/realtimeProxyRegistry.d.ts.map +1 -1
  23. package/dist/generic/realtimeProxyRegistry.js +10 -0
  24. package/dist/generic/realtimeProxyRegistry.js.map +1 -1
  25. package/dist/generic/realtimeToolBatchBarrier.d.ts +67 -0
  26. package/dist/generic/realtimeToolBatchBarrier.d.ts.map +1 -0
  27. package/dist/generic/realtimeToolBatchBarrier.js +119 -0
  28. package/dist/generic/realtimeToolBatchBarrier.js.map +1 -0
  29. package/dist/generic/toolTurnEncoding.d.ts +26 -0
  30. package/dist/generic/toolTurnEncoding.d.ts.map +1 -0
  31. package/dist/generic/toolTurnEncoding.js +46 -0
  32. package/dist/generic/toolTurnEncoding.js.map +1 -0
  33. package/dist/index.d.ts +3 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +3 -0
  36. package/dist/index.js.map +1 -1
  37. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"modelConfiguration.d.ts","sourceRoot":"","sources":["../../src/generic/modelConfiguration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,EAAE,UAAU,EAAa,MAAM,gBAAgB,CAAC;AAEvD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,GAAG,QAAQ,CAAC;AAE3F;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC1C,iDAAiD;IACjD,IAAI,CAAC,EAAE,yBAAyB,CAAC;IACjC,+FAA+F;IAC/F,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IACpC,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yFAAyF;IACzF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,mGAAmG;AACnG,MAAM,WAAW,iCAAiC;IAC9C;;;;OAIG;IACH,aAAa,CAAC,EAAE,6BAA6B,CAAC;CACjD;AAED;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B;IACzC,6DAA6D;IAC7D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC,uCAAuC;IACvC,GAAG,CAAC,EAAE,4BAA4B,CAAC;IACnC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,iCAAiC,CAAC;IAC7C,8BAA8B;IAC9B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,uCAAuC;IACvC,KAAK,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,wBAAgB,uB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;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,uBAAuB,CAAC;AAEjE,iGAAiG;AACjG,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,CAAC;AAE9E,4FAA4F;AAC5F,MAAM,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AACpE;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,oBAAoB,GAAG,IAAI,CAUpG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kCAAkC,CAC9C,GAAG,MAAM,EAAE,KAAK,CAAC,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC,GAC1D,oBAAoB,GAAG,IAAI,CAS7B"}
@@ -1,9 +1,8 @@
1
1
  /**
2
- * The canonical `ModelConfiguration` shape + the pure cascade resolver.
2
+ * The canonical AI configuration shapes + the pure cascade resolvers.
3
3
  *
4
- * `ModelConfiguration` is a JSONType `nvarchar(max)` column that exists at THREE levels of the
5
- * model catalog, forming an inherit-with-override cascade (the structured generalization of the
6
- * scalar `SupportsPrefill` / `PrefillFallbackText` cascade those same three entities already carry):
4
+ * The AI stack carries `nvarchar(max)` JSONType configuration bags at five levels, in two cascades.
5
+ * The MODEL CATALOG cascade describes the model:
7
6
  *
8
7
  * ```
9
8
  * MJ: AI Model Types . ModelConfiguration (type-wide default — e.g. every Realtime model)
@@ -11,16 +10,28 @@
11
10
  * < MJ: AI Model Vendors . ModelConfiguration (per model-on-this-provider — the winner)
12
11
  * ```
13
12
  *
14
- * **Lockstep contract**: this interface is the package-side mirror of
15
- * `metadata/entities/JSONType-interfaces/IAIModelConfiguration.ts`, which is pushed into
16
- * `EntityField.JSONTypeDefinition` and drives the CodeGen-generated `ModelConfigurationObject`
17
- * accessors on the three entities. Keep the two in step when adding a section or property —
18
- * the same pact `IAgentSettings` follows with `@memberjunction/ai-core-plus`.
13
+ * The PROMPT cascade describes what a given prompt asks for, and layers on top of the catalog:
14
+ *
15
+ * ```
16
+ * MJ: AI Prompts . PromptConfiguration (per-prompt)
17
+ * < MJ: AI Prompt Models . PromptConfiguration (per prompt-on-this-model — the winner)
18
+ * ```
19
+ *
20
+ * Both compose the SAME per-modality section types ({@link LLMConfigurationSettings},
21
+ * {@link RealtimeConfigurationSettings}, …) — one definition of what "the LLM configuration" means,
22
+ * reused at every layer. Only the outer per-table type differs.
23
+ *
24
+ * **Lockstep contract**: these interfaces mirror
25
+ * `metadata/entities/JSONType-interfaces/IAIConfiguration.ts`, which is pushed into
26
+ * `EntityField.JSONTypeDefinition` and drives the CodeGen-generated `ModelConfigurationObject` /
27
+ * `PromptConfigurationObject` accessors on the five entities. Keep the two in step when adding a section
28
+ * or property — the same pact `IAgentSettings` follows with `@memberjunction/ai-core-plus`.
19
29
  *
20
30
  * **Boundary rule** (also documented on the metadata interface): anything the engine filters,
21
31
  * sorts, or joins on stays a COLUMN (`PowerRank`, `IsActive`, `Priority`, `Status` — SQL cannot
22
- * cheaply predicate into this bag); anything a driver consumes at session/call time belongs HERE.
23
- * New capability knobs go in this bag — do not add a new capability column per knob.
32
+ * cheaply predicate into this bag); anything a driver or runner consumes at call time belongs HERE.
33
+ * New capability knobs go in the bag — do not add a capability column per knob. A knob graduates to
34
+ * a real column when it needs a foreign key or becomes a first-class platform concept.
24
35
  */
25
36
  import { IsPlainObject } from '@memberjunction/global';
26
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"modelConfiguration.js","sourceRoot":"","sources":["../../src/generic/modelConfiguration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAyEvD;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAA+B;IACnE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,E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provider.
3
+ *
4
+ * OpenAI's function-calling shape is the de-facto standard: Groq, Cerebras, Fireworks, xAI,
5
+ * Together, LM Studio, DeepSeek, Moonshot, Z.AI, MiniMax and OpenRouter all speak it. The mapping
6
+ * between MJ's neutral surface and that shape is therefore written **once, here**, rather than
7
+ * per driver.
8
+ *
9
+ * That matters more than it saves. The mapping has three details that are easy to get subtly
10
+ * wrong and impossible to notice from a passing test:
11
+ *
12
+ * 1. arguments cross the wire as a **JSON string**, not an object;
13
+ * 2. a tool RESULT is its own `tool`-role message with a `tool_call_id`, so one MJ tool turn
14
+ * expands into N provider messages;
15
+ * 3. a call whose arguments are malformed JSON must still be **surfaced**, because an agent loop
16
+ * that sees nothing cannot tell "the model said nothing" from "the model said something broken".
17
+ *
18
+ * Three implementations of that would drift. One cannot.
19
+ *
20
+ * These functions return plain structural objects rather than any SDK's types, because every
21
+ * provider ships its own near-identical copies. Each driver assigns the result into its own SDK
22
+ * type at the boundary, which is where the compiler can still check the shape.
23
+ */
24
+ import type { ChatMessage, ChatTool, ChatToolCall, ChatToolChoice } from './chat.types.js';
25
+ /** A tool declaration in the OpenAI-compatible request body. */
26
+ export interface OpenAICompatibleToolDeclaration {
27
+ type: 'function';
28
+ function: {
29
+ name: string;
30
+ description?: string;
31
+ parameters: Record<string, unknown>;
32
+ };
33
+ }
34
+ /** The `tool_choice` field. The string forms pass through; only the named form is reshaped. */
35
+ export type OpenAICompatibleToolChoice = 'auto' | 'none' | 'required' | {
36
+ type: 'function';
37
+ function: {
38
+ name: string;
39
+ };
40
+ };
41
+ /**
42
+ * A tool call as it arrives on an assistant turn — note `arguments` is a JSON STRING.
43
+ *
44
+ * The index signature is deliberate. Provider SDKs declare their own near-identical copies of this
45
+ * shape, several of them WITH an open index signature (Cerebras does), and a closed type is not
46
+ * assignable to an open one. Declaring these wire types open keeps them assignable in both
47
+ * directions, which is what lets one mapping serve every OpenAI-shaped provider — and it is honest
48
+ * about what they are: a body providers are free to extend.
49
+ */
50
+ export interface OpenAICompatibleToolCall {
51
+ id: string;
52
+ type: 'function';
53
+ function: {
54
+ name: string;
55
+ arguments: string;
56
+ };
57
+ [key: string]: unknown;
58
+ }
59
+ /** One `tool`-role message carrying the result of one call. */
60
+ export interface OpenAICompatibleToolResultMessage {
61
+ role: 'tool';
62
+ tool_call_id: string;
63
+ content: string;
64
+ [key: string]: unknown;
65
+ }
66
+ /**
67
+ * A non-tool message in the OpenAI-compatible request body.
68
+ *
69
+ * Discriminated on `role` rather than a single interface with a union-typed role, because every
70
+ * provider SDK models it that way — a flat interface fails to narrow when assigned to theirs.
71
+ * `tool_calls` rides on the assistant turn; without it the `tool` messages answering those calls
72
+ * are orphaned and the provider rejects the conversation.
73
+ */
74
+ export type OpenAICompatibleChatMessage = {
75
+ role: 'system';
76
+ content: string;
77
+ [key: string]: unknown;
78
+ } | {
79
+ role: 'user';
80
+ content: string;
81
+ [key: string]: unknown;
82
+ } | {
83
+ role: 'assistant';
84
+ content: string;
85
+ tool_calls?: OpenAICompatibleToolCall[];
86
+ [key: string]: unknown;
87
+ };
88
+ /** Any message in an OpenAI-compatible request body. */
89
+ export type OpenAICompatibleMessage = OpenAICompatibleChatMessage | OpenAICompatibleToolResultMessage;
90
+ /** The subset of a raw response tool call this module can read, whatever SDK produced it. */
91
+ export interface RawOpenAICompatibleToolCall {
92
+ id?: string;
93
+ type?: string;
94
+ function?: {
95
+ name?: string;
96
+ arguments?: string;
97
+ };
98
+ }
99
+ /** Maps MJ tool declarations onto the request's `tools` array. */
100
+ export declare function buildOpenAICompatibleTools(tools: ChatTool[]): OpenAICompatibleToolDeclaration[];
101
+ /** Maps the neutral {@link ChatToolChoice} onto the provider's `tool_choice`. */
102
+ export declare function buildOpenAICompatibleToolChoice(choice: ChatToolChoice): OpenAICompatibleToolChoice;
103
+ /**
104
+ * Maps normalized calls from a prior assistant turn back onto the wire.
105
+ *
106
+ * Round-tripping matters: without the assistant's `tool_calls`, the `tool` messages answering them
107
+ * are orphaned and the provider rejects the conversation.
108
+ */
109
+ export declare function buildOpenAICompatibleToolCalls(toolCalls: ChatToolCall[]): OpenAICompatibleToolCall[];
110
+ /**
111
+ * Expands one MJ `tool`-role message into the provider's per-result `tool` messages.
112
+ *
113
+ * Returns an empty array — and warns — for a tool turn carrying no result blocks, rather than
114
+ * emitting a malformed message the provider would reject with an opaque error.
115
+ */
116
+ export declare function buildOpenAICompatibleToolResults(message: ChatMessage, providerName: string): OpenAICompatibleToolResultMessage[];
117
+ /**
118
+ * Normalizes raw response tool calls into {@link ChatToolCall}s with PARSED arguments.
119
+ *
120
+ * A model can emit malformed JSON for its arguments. That is a tool-specific failure the caller
121
+ * must be able to see, so the call is surfaced with empty arguments and a warning rather than
122
+ * dropped — dropping it would look to an agent loop like the model said nothing at all.
123
+ *
124
+ * @param toolCalls Raw calls from the response, if any
125
+ * @param providerName Used only in the warning, so a log line names the provider
126
+ * @returns Normalized calls, or `undefined` when the model called nothing
127
+ */
128
+ export declare function extractOpenAICompatibleToolCalls(toolCalls: RawOpenAICompatibleToolCall[] | undefined | null, providerName: string): ChatToolCall[] | undefined;
129
+ //# sourceMappingURL=openAICompatibleTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAICompatibleTools.d.ts","sourceRoot":"","sources":["../../src/generic/openAICompatibleTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGxF,gEAAgE;AAChE,MAAM,WAAW,+BAA+B;IAC5C,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACvC,CAAC;CACL;AAED,+FAA+F;AAC/F,MAAM,MAAM,0BAA0B,GAChC,MA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AAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,kEAAkE;AAClE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,+BAA+B,EAAE,CAS/F;AAED,iFAAiF;AACjF,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,cAAc,GAAG,0BAA0B,CAIlG;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,wBAAwB,EAAE,CASpG;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC5C,OAAO,EAAE,WAAW,EACpB,YAAY,EAAE,MAAM,GACrB,iCAAiC,EAAE,CAarC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAC5C,SAAS,EAAE,2BAA2B,EAAE,GAAG,SAAS,GAAG,IAAI,EAC3D,YAAY,EAAE,MAAM,GACrB,YAAY,EAAE,GAAG,SAAS,CA0B5B"}
@@ -0,0 +1,94 @@
1
+ import { getToolResultBlocks } from './chat.types.js';
2
+ /** Maps MJ tool declarations onto the request's `tools` array. */
3
+ export function buildOpenAICompatibleTools(tools) {
4
+ return tools.map((tool) => ({
5
+ type: 'function',
6
+ function: {
7
+ name: tool.name,
8
+ description: tool.description,
9
+ parameters: tool.inputSchema
10
+ }
11
+ }));
12
+ }
13
+ /** Maps the neutral {@link ChatToolChoice} onto the provider's `tool_choice`. */
14
+ export function buildOpenAICompatibleToolChoice(choice) {
15
+ return typeof choice === 'string'
16
+ ? choice
17
+ : { type: 'function', function: { name: choice.name } };
18
+ }
19
+ /**
20
+ * Maps normalized calls from a prior assistant turn back onto the wire.
21
+ *
22
+ * Round-tripping matters: without the assistant's `tool_calls`, the `tool` messages answering them
23
+ * are orphaned and the provider rejects the conversation.
24
+ */
25
+ export function buildOpenAICompatibleToolCalls(toolCalls) {
26
+ return toolCalls.map((call) => ({
27
+ id: call.id,
28
+ type: 'function',
29
+ function: {
30
+ name: call.name,
31
+ arguments: JSON.stringify(call.arguments ?? {})
32
+ }
33
+ }));
34
+ }
35
+ /**
36
+ * Expands one MJ `tool`-role message into the provider's per-result `tool` messages.
37
+ *
38
+ * Returns an empty array — and warns — for a tool turn carrying no result blocks, rather than
39
+ * emitting a malformed message the provider would reject with an opaque error.
40
+ */
41
+ export function buildOpenAICompatibleToolResults(message, providerName) {
42
+ const blocks = getToolResultBlocks(message.content);
43
+ if (blocks.length === 0) {
44
+ console.warn(`${providerName}: a tool-role message carried no tool_result blocks; skipping it.`);
45
+ return [];
46
+ }
47
+ return blocks.map((block) => ({
48
+ role: 'tool',
49
+ tool_call_id: block.toolCallId,
50
+ // This wire shape has no error flag on a tool result, so a failure has to be marked in the
51
+ // text or the model cannot tell a failure from a result.
52
+ content: block.isError ? `ERROR: ${block.content}` : block.content
53
+ }));
54
+ }
55
+ /**
56
+ * Normalizes raw response tool calls into {@link ChatToolCall}s with PARSED arguments.
57
+ *
58
+ * A model can emit malformed JSON for its arguments. That is a tool-specific failure the caller
59
+ * must be able to see, so the call is surfaced with empty arguments and a warning rather than
60
+ * dropped — dropping it would look to an agent loop like the model said nothing at all.
61
+ *
62
+ * @param toolCalls Raw calls from the response, if any
63
+ * @param providerName Used only in the warning, so a log line names the provider
64
+ * @returns Normalized calls, or `undefined` when the model called nothing
65
+ */
66
+ export function extractOpenAICompatibleToolCalls(toolCalls, providerName) {
67
+ if (!toolCalls || toolCalls.length === 0) {
68
+ return undefined;
69
+ }
70
+ const calls = [];
71
+ for (const call of toolCalls) {
72
+ // Custom (non-function) tool types are not part of the neutral surface.
73
+ if (call.type !== undefined && call.type !== 'function') {
74
+ continue;
75
+ }
76
+ const name = call.function?.name;
77
+ if (!name) {
78
+ continue;
79
+ }
80
+ let parsedArguments = {};
81
+ try {
82
+ const parsed = JSON.parse(call.function?.arguments || '{}');
83
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
84
+ parsedArguments = parsed;
85
+ }
86
+ }
87
+ catch {
88
+ console.warn(`${providerName}: could not parse arguments for tool call '${name}'; surfacing the call with empty arguments.`);
89
+ }
90
+ calls.push({ id: call.id ?? '', name, arguments: parsedArguments });
91
+ }
92
+ return calls.length > 0 ? calls : undefined;
93
+ }
94
+ //# sourceMappingURL=openAICompatibleTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAICompatibleTools.js","sourceRoot":"","sources":["../../src/generic/openAICompatibleTools.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAqEnD,kEAAkE;AAClE,MAAM,UAAU,0BAA0B,CAAC,KAAiB;IACxD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxB,IAAI,EAAE,UAAmB;QACzB,QAAQ,EAAE;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,WAAW;SAC/B;KACJ,CAAC,CAAC,CAAC;AACR,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,+BAA+B,CAAC,MAAsB;IAClE,OAAO,OAAO,MAAM,KAAK,QAAQ;QAC7B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,EAAE,IAAI,EAAE,UAAmB,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;AACzE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAAC,SAAyB;IACpE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5B,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,UAAmB;QACzB,QAAQ,EAAE;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,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QAClD,IAAI,CAAC;YACD,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,CAAC;YACrE,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjE,eAAe,GAAG,MAAiC,CAAC;YACxD,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,8CAA8C,IAAI,6CAA6C,CAAC,CAAC;QACjI,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC"}
@@ -5,6 +5,14 @@ import { BaseSingleton } from '@memberjunction/global';
5
5
  * (in Core) so the minting side (driver) and the serving side (MJServer proxy) can never drift.
6
6
  */
7
7
  export declare const REALTIME_PROXY_PATH = "/realtime-proxy";
8
+ /**
9
+ * The URL path MJAPI's realtime WebRTC SDP broker listens on for offer/answer exchanges.
10
+ */
11
+ export declare const REALTIME_SDP_EXCHANGE_PATH = "/realtime/sdp-exchange";
12
+ /**
13
+ * @deprecated Use `REALTIME_SDP_EXCHANGE_PATH`.
14
+ */
15
+ export declare const OPENAI_LIVE_SDP_EXCHANGE_PATH = "/realtime/sdp-exchange";
8
16
  /**
9
17
  * A short-lived, one-time authorization to open ONE upstream realtime websocket through the
10
18
  * MJAPI realtime proxy. Stored server-side only — the upstream URL and (optional) auth header
@@ -28,6 +36,13 @@ export interface RealtimeProxyTicketEntry {
28
36
  UpstreamAuthHeader?: string;
29
37
  /** The MJ user this ticket was minted for (for audit / optional validation at consume time). */
30
38
  UserID?: string;
39
+ /** The driver class authorizing this ticket (e.g. 'OpenAILiveRealtime'). */
40
+ DriverClass?: string;
41
+ /**
42
+ * Authoritative session configuration minted by the server (e.g. for WebRTC SDP exchanges).
43
+ * Prevents clients from tampering with upstream model, reasoning, or tools.
44
+ */
45
+ SessionConfig?: Record<string, unknown>;
31
46
  /** Epoch-ms after which the ticket is invalid. Enforced on {@link RealtimeProxyRegistry.Consume}. */
32
47
  ExpiresAtMs: number;
33
48
  }
@@ -39,6 +54,10 @@ export interface RealtimeProxyIssueParams {
39
54
  UpstreamAuthHeader?: string;
40
55
  /** The MJ user the ticket is for (optional). */
41
56
  UserID?: string;
57
+ /** The driver class authorizing this ticket (optional). */
58
+ DriverClass?: string;
59
+ /** Authoritative session configuration minted by the server (optional). */
60
+ SessionConfig?: Record<string, unknown>;
42
61
  /** Time-to-live, in seconds, for the ONE upstream open this ticket authorizes. */
43
62
  TTLSeconds: number;
44
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"realtimeProxyRegistry.d.ts","sourceRoot":"","sources":["../../src/generic/realtimeProxyRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,wBAAwB;IACrC,uGAAuG;IACvG,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gGAAgG;IAChG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qGAAqG;IACrG,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,yFAAyF;AACzF,MAAM,WAAW,wBAAwB;IACrC,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,MAAM,C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AAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,qGAAqG;IACrG,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,yFAAyF;AACzF,MAAM,WAAW,wBAAwB;IACrC,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,wGAAwG;AACxG,MAAM,WAAW,mBAAmB;IAChC,4FAA4F;IAC5F,EAAE,EAAE,MAAM,CAAC;IACX,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAsB,SAAQ,aAAa,CAAC,qBAAqB,CAAC;IAC3E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoD;IAE7E,SAAS;IAIT,uCAAuC;IACvC,WAAkB,QAAQ,IAAI,qBAAqB,CAElD;IAED;;;OAGG;IACI,KAAK,CAAC,MAAM,EAAE,wBAAwB,GAAG,mBAAmB;IAenE;;;;OAIG;IACI,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,wBAAwB,GAAG,IAAI;IAgB3D,wFAAwF;IACxF,IAAW,KAAK,IAAI,MAAM,CAGzB;IAED,kDAAkD;IAClD,OAAO,CAAC,YAAY;IASpB,0FAA0F;IAC1F,OAAO,CAAC,MAAM,CAAC,WAAW;CAY7B"}
@@ -5,6 +5,14 @@ import { BaseSingleton } from '@memberjunction/global';
5
5
  * (in Core) so the minting side (driver) and the serving side (MJServer proxy) can never drift.
6
6
  */
7
7
  export const REALTIME_PROXY_PATH = '/realtime-proxy';
8
+ /**
9
+ * The URL path MJAPI's realtime WebRTC SDP broker listens on for offer/answer exchanges.
10
+ */
11
+ export const REALTIME_SDP_EXCHANGE_PATH = '/realtime/sdp-exchange';
12
+ /**
13
+ * @deprecated Use `REALTIME_SDP_EXCHANGE_PATH`.
14
+ */
15
+ export const OPENAI_LIVE_SDP_EXCHANGE_PATH = REALTIME_SDP_EXCHANGE_PATH;
8
16
  /**
9
17
  * Process-wide, in-memory registry of one-time realtime-proxy tickets (Global Object Store backed
10
18
  * via {@link BaseSingleton}, so the provider driver that mints and the MJAPI proxy that consumes
@@ -39,6 +47,8 @@ export class RealtimeProxyRegistry extends BaseSingleton {
39
47
  UpstreamUrl: params.UpstreamUrl,
40
48
  UpstreamAuthHeader: params.UpstreamAuthHeader,
41
49
  UserID: params.UserID,
50
+ DriverClass: params.DriverClass,
51
+ SessionConfig: params.SessionConfig,
42
52
  ExpiresAtMs: expiresAtMs,
43
53
  });
44
54
  return { ID: id, ExpiresAt: new Date(expiresAtMs).toISOString() };
@@ -1 +1 @@
1
- {"version":3,"file":"realtimeProxyRegistry.js","sourceRoot":"","sources":["../../src/generic/realtimeProxyRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAiDrD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAoC;IAG3E;QACI,KAAK,EAAE,CAAC;QAHK,aAAQ,GAA0C,IAAI,GAAG,EAAE,CAAC;IAI7E,CAAC;IAED,uCAAuC;IAChC,MAAM,KAAK,QAAQ;QACtB,OAAO,KAAK,CAAC,WAAW,EAAyB,CAAC;IACtD,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,MAAgC;QACzC,IAAI,CAAC,YAAY,EAAE,CAA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AAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Coordinates batched tool-call completions for realtime sessions that require
3
+ * a single turn-continuation trigger (e.g. OpenAI Live `response.create`) per
4
+ * batch of parallel tool calls, rather than firing per tool result.
5
+ *
6
+ * Requirements (§4.2 / §4.3 of plans/realtime/gpt-live-1.md):
7
+ * - Multiple parallel tool calls arrive in a single turn.
8
+ * - Each tool output must be appended (e.g. `response.item.create`).
9
+ * - Exactly ONE `response.create` must be sent when the outstanding set drains.
10
+ * - A safety timeout ensures a lost or unreturned tool call does not wedge the session indefinitely.
11
+ * - Unknown or duplicate results for already closed calls never re-fire response.create.
12
+ */
13
+ export declare class RealtimeToolBatchBarrier {
14
+ private _outstanding;
15
+ private _timer;
16
+ private _onTimeoutFlush?;
17
+ private _timeoutMs;
18
+ /**
19
+ * @param defaultTimeoutMs Maximum time in milliseconds to wait for remaining tool results before flushing (default 15s).
20
+ */
21
+ constructor(defaultTimeoutMs?: number);
22
+ /**
23
+ * Records an outstanding tool call ID that must be answered.
24
+ * @param callId The tool call identifier.
25
+ * @param onTimeoutFlush Optional callback to invoke if the batch times out waiting for remaining results.
26
+ */
27
+ Opened(callId: string, onTimeoutFlush?: () => void): void;
28
+ /**
29
+ * Alias for Opened.
30
+ */
31
+ TrackPendingCall(callId: string, onTimeoutFlush?: () => void): void;
32
+ /**
33
+ * Returns true when THIS result drains the batch and the caller should send response.create.
34
+ * If the call was not in the outstanding set (unknown or duplicate), returns false.
35
+ *
36
+ * @param callId The tool call identifier.
37
+ */
38
+ Closed(callId: string): boolean;
39
+ /**
40
+ * Alias for Closed.
41
+ */
42
+ RecordResult(callId: string): boolean;
43
+ /**
44
+ * Returns true if there are no outstanding tool calls.
45
+ */
46
+ get IsEmpty(): boolean;
47
+ /**
48
+ * Number of tool calls still awaiting results in the current batch.
49
+ */
50
+ get PendingCount(): number;
51
+ /**
52
+ * Arms or re-arms the timeout with a custom duration and callback.
53
+ */
54
+ ArmTimeout(ms: number, onTimeoutFlush: () => void): void;
55
+ /**
56
+ * Resets the barrier state and cancels any pending timeout (alias for Clear).
57
+ */
58
+ Reset(): void;
59
+ /**
60
+ * Clears all pending tool calls and cancels any active timeout (e.g. on user interruption,
61
+ * error, or session close).
62
+ */
63
+ Clear(): void;
64
+ private resetTimeout;
65
+ private clearTimeout;
66
+ }
67
+ //# sourceMappingURL=realtimeToolBatchBarrier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtimeToolBatchBarrier.d.ts","sourceRoot":"","sources":["../../src/generic/realtimeToolBatchBarrier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,qBAAa,wBAAwB;IACjC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,MAAM,CAA8C;IAC5D,OAAO,CAAC,eAAe,CAAC,CAAa;IACrC,OAAO,CAAC,UAAU,CAAS;IAE3B;;OAEG;gBACS,gBAAgB,GAAE,MAAc;IAI5C;;;;OAIG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAWhE;;OAEG;IACI,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAI1E;;;;;OAKG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAYtC;;OAEG;IACI,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5C;;OAEG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;OAEG;IACH,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED;;OAEG;IACI,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,IAAI,GAAG,IAAI;IAM/D;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB;;;OAGG;IACI,KAAK,IAAI,IAAI;IAKpB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,YAAY;CAMvB"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Coordinates batched tool-call completions for realtime sessions that require
3
+ * a single turn-continuation trigger (e.g. OpenAI Live `response.create`) per
4
+ * batch of parallel tool calls, rather than firing per tool result.
5
+ *
6
+ * Requirements (§4.2 / §4.3 of plans/realtime/gpt-live-1.md):
7
+ * - Multiple parallel tool calls arrive in a single turn.
8
+ * - Each tool output must be appended (e.g. `response.item.create`).
9
+ * - Exactly ONE `response.create` must be sent when the outstanding set drains.
10
+ * - A safety timeout ensures a lost or unreturned tool call does not wedge the session indefinitely.
11
+ * - Unknown or duplicate results for already closed calls never re-fire response.create.
12
+ */
13
+ export class RealtimeToolBatchBarrier {
14
+ /**
15
+ * @param defaultTimeoutMs Maximum time in milliseconds to wait for remaining tool results before flushing (default 15s).
16
+ */
17
+ constructor(defaultTimeoutMs = 15000) {
18
+ this._outstanding = new Set();
19
+ this._timer = null;
20
+ this._timeoutMs = defaultTimeoutMs;
21
+ }
22
+ /**
23
+ * Records an outstanding tool call ID that must be answered.
24
+ * @param callId The tool call identifier.
25
+ * @param onTimeoutFlush Optional callback to invoke if the batch times out waiting for remaining results.
26
+ */
27
+ Opened(callId, onTimeoutFlush) {
28
+ if (!callId) {
29
+ return;
30
+ }
31
+ this._outstanding.add(callId);
32
+ if (onTimeoutFlush) {
33
+ this._onTimeoutFlush = onTimeoutFlush;
34
+ }
35
+ this.resetTimeout();
36
+ }
37
+ /**
38
+ * Alias for Opened.
39
+ */
40
+ TrackPendingCall(callId, onTimeoutFlush) {
41
+ this.Opened(callId, onTimeoutFlush);
42
+ }
43
+ /**
44
+ * Returns true when THIS result drains the batch and the caller should send response.create.
45
+ * If the call was not in the outstanding set (unknown or duplicate), returns false.
46
+ *
47
+ * @param callId The tool call identifier.
48
+ */
49
+ Closed(callId) {
50
+ if (!this._outstanding.delete(callId)) {
51
+ return false; // unknown or duplicate result — never re-fire
52
+ }
53
+ if (this._outstanding.size === 0) {
54
+ this.clearTimeout();
55
+ return true;
56
+ }
57
+ this.resetTimeout();
58
+ return false;
59
+ }
60
+ /**
61
+ * Alias for Closed.
62
+ */
63
+ RecordResult(callId) {
64
+ return this.Closed(callId);
65
+ }
66
+ /**
67
+ * Returns true if there are no outstanding tool calls.
68
+ */
69
+ get IsEmpty() {
70
+ return this._outstanding.size === 0;
71
+ }
72
+ /**
73
+ * Number of tool calls still awaiting results in the current batch.
74
+ */
75
+ get PendingCount() {
76
+ return this._outstanding.size;
77
+ }
78
+ /**
79
+ * Arms or re-arms the timeout with a custom duration and callback.
80
+ */
81
+ ArmTimeout(ms, onTimeoutFlush) {
82
+ this._timeoutMs = ms;
83
+ this._onTimeoutFlush = onTimeoutFlush;
84
+ this.resetTimeout();
85
+ }
86
+ /**
87
+ * Resets the barrier state and cancels any pending timeout (alias for Clear).
88
+ */
89
+ Reset() {
90
+ this.Clear();
91
+ }
92
+ /**
93
+ * Clears all pending tool calls and cancels any active timeout (e.g. on user interruption,
94
+ * error, or session close).
95
+ */
96
+ Clear() {
97
+ this._outstanding.clear();
98
+ this.clearTimeout();
99
+ }
100
+ resetTimeout() {
101
+ this.clearTimeout();
102
+ if (this._outstanding.size > 0 && this._onTimeoutFlush) {
103
+ this._timer = setTimeout(() => {
104
+ this._timer = null;
105
+ if (this._outstanding.size > 0) {
106
+ this._outstanding.clear();
107
+ this._onTimeoutFlush?.();
108
+ }
109
+ }, this._timeoutMs);
110
+ }
111
+ }
112
+ clearTimeout() {
113
+ if (this._timer) {
114
+ clearTimeout(this._timer);
115
+ this._timer = null;
116
+ }
117
+ }
118
+ }
119
+ //# sourceMappingURL=realtimeToolBatchBarrier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtimeToolBatchBarrier.js","sourceRoot":"","sources":["../../src/generic/realtimeToolBatchBarrier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,wBAAwB;IAMjC;;OAEG;IACH,YAAY,mBAA2B,KAAK;QARpC,iBAAY,GAA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CAAC,EAAU,EAAE,cAA0B;QACpD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,KAAK;QACR,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;IAED;;;OAGG;IACI,KAAK;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAEO,YAAY;QAChB,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACrD,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;oBAC7B,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;oBAC1B,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC;gBAC7B,CAAC;YACL,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACxB,CAAC;IACL,CAAC;IAEO,YAAY;QAChB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Re-encodes native tool turns as plain text — the form a model sees when it is NOT given tool
3
+ * declarations.
4
+ *
5
+ * A conversation that ran natively holds an assistant turn carrying `toolCalls` and a `tool` turn of
6
+ * `tool_result` blocks. Providers accept those only alongside tool declarations (and Gemini also
7
+ * polices their order), so a request that strips the declarations but keeps the turns fails for a
8
+ * second, unrelated reason. This is the one encoding for that history the envelope path has always
9
+ * used: the call turn keeps only its prose (the agent loop never appends the model's own call turn on
10
+ * the envelope path), and each result becomes a user message of the loop's
11
+ * `[Action Result] <tool> succeeded|failed. <content>` form.
12
+ *
13
+ * Used by the prompt runner's native→envelope fallback and by the eval harness, which writes each
14
+ * multi-turn case once in the neutral tool form and renders it per arm.
15
+ *
16
+ * @module generic/toolTurnEncoding
17
+ */
18
+ import type { ChatMessage } from './chat.types.js';
19
+ /** Prefix of the user message a tool result becomes. */
20
+ export declare const ACTION_RESULT_TEXT_PREFIX = "[Action Result]";
21
+ /**
22
+ * Returns a copy of `messages` with every native tool turn rendered as text. Messages that carry no
23
+ * tool turn are passed through untouched (same object), so an already-textual history is unchanged.
24
+ */
25
+ export declare function EncodeToolTurnsAsText(messages: readonly ChatMessage[]): ChatMessage[];
26
+ //# sourceMappingURL=toolTurnEncoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolTurnEncoding.d.ts","sourceRoot":"","sources":["../../src/generic/toolTurnEncoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,cAAc,CAAC;AAEzE,wDAAwD;AACxD,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAS3D;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,EAAE,CA4BrF"}