@saga-a2ui/core 0.7.7-rc.1 → 0.8.0-rc.1
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 +1 -1
- package/package.json +1 -1
- package/src/conversation.ts +74 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @saga-a2ui/core
|
|
2
2
|
|
|
3
|
-
Renderer-independent actions and A2UI v0.9 decoding. Entry points: `/actions`, `/actions/action-button-schema`, `/delivered-result` (the neutral whole-result type a delivery hands a view), `/host-links`, `/protocols/a2ui/v0_9`, `/protocols/a2ui/zod3`.
|
|
3
|
+
Renderer-independent actions and A2UI v0.9 decoding. Entry points: `/actions`, `/actions/action-button-schema`, `/conversation` (the contract by which a view adds a message to the conversation), `/delivered-result` (the neutral whole-result type a delivery hands a view), `/host-links`, `/protocols/a2ui/v0_9`, `/protocols/a2ui/zod3`.
|
|
4
4
|
|
|
5
5
|
Requires Node >=22.12.0 and a TypeScript-aware bundler; exports are TypeScript source. Apache-2.0, with dependency licenses retained separately.
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@saga-a2ui/core","private":false,"description":"Renderer-independent SAGA A2UI processing: version-specific decoding, validated message cases and the message session, and the renderer-independent action runtime (local and server actions, prerequisites, bounded hooks, resource ownership) at /actions","license":"Apache-2.0","type":"module","exports":{"./actions":"./src/actions/index.ts","./actions/action-button-schema":"./src/actions/action-button-schema.ts","./delivered-result":"./src/delivered-result.ts","./host-links":"./src/host-links.ts","./protocols/a2ui/v0_9":"./src/protocols/a2ui/v0_9/index.ts","./protocols/a2ui/zod3":"./src/protocols/a2ui/zod3.ts"},"files":["src","!src/**/*.test.ts","!src/**/*.test-support.ts"],"scripts":{"typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json"},"dependencies":{"@a2ui/web_core":"0.13.0","zod3":"npm:zod@3.25.76"},"devDependencies":{"@types/node":"22.20.5","typescript":"^5.9.0","vitest":"^5.0.4"},"version":"0.
|
|
1
|
+
{"name":"@saga-a2ui/core","private":false,"description":"Renderer-independent SAGA A2UI processing: version-specific decoding, validated message cases and the message session, and the renderer-independent action runtime (local and server actions, prerequisites, bounded hooks, resource ownership) at /actions","license":"Apache-2.0","type":"module","exports":{"./actions":"./src/actions/index.ts","./actions/action-button-schema":"./src/actions/action-button-schema.ts","./conversation":"./src/conversation.ts","./delivered-result":"./src/delivered-result.ts","./host-links":"./src/host-links.ts","./protocols/a2ui/v0_9":"./src/protocols/a2ui/v0_9/index.ts","./protocols/a2ui/zod3":"./src/protocols/a2ui/zod3.ts"},"files":["src","!src/**/*.test.ts","!src/**/*.test-support.ts"],"scripts":{"typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json"},"dependencies":{"@a2ui/web_core":"0.13.0","zod3":"npm:zod@3.25.76"},"devDependencies":{"@types/node":"22.20.5","typescript":"^5.9.0","vitest":"^5.0.4"},"version":"0.8.0-rc.1","engines":{"node":">=22.12.0"},"repository":{"type":"git","url":"https://github.com/MachineWisdomAI/saga-a2ui.git","directory":"packages/core"},"publishConfig":{"access":"public","tag":"next"}}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// How a view adds a message to the conversation around it. The contract is renderer- and
|
|
2
|
+
// delivery-neutral, like the host link contract: an application consumes it, a delivery (MCP Apps
|
|
3
|
+
// today) supplies an implementation, and neither depends on the other.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What happened to one request the host was asked to carry out.
|
|
7
|
+
*
|
|
8
|
+
* - `denied`: the host refused it (the person declined, a policy blocked it).
|
|
9
|
+
* - `unavailable`: the host advertises no capability for the request, or the view has ended. That
|
|
10
|
+
* request was not sent.
|
|
11
|
+
* - `failed`: the request could not complete (connection lost, timeout). Whether the host acted on
|
|
12
|
+
* it is unknown.
|
|
13
|
+
*/
|
|
14
|
+
export type RequestOutcome = 'denied' | 'unavailable' | 'failed';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The result of `appendMessage`.
|
|
18
|
+
*
|
|
19
|
+
* - `appended`: the host accepted the message. It does not show that the assistant replied, or
|
|
20
|
+
* what it said. `context` is set only when a best-effort context was skipped, and says why.
|
|
21
|
+
* - Any other outcome means nothing was appended. `stage` says which request stopped the append.
|
|
22
|
+
*/
|
|
23
|
+
export type AppendResult =
|
|
24
|
+
| {
|
|
25
|
+
readonly outcome: 'appended';
|
|
26
|
+
readonly context?: RequestOutcome;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
readonly outcome: RequestOutcome;
|
|
30
|
+
readonly stage: 'context' | 'message';
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The only way a view reaches the conversation: add a message as the person, which gives the
|
|
35
|
+
* assistant its turn. A view receives its own instance explicitly.
|
|
36
|
+
*/
|
|
37
|
+
export interface Conversation {
|
|
38
|
+
/**
|
|
39
|
+
* Adds a message to the conversation as the person, which gives the assistant its turn.
|
|
40
|
+
* `context` is information for that turn that the conversation does not show. By default the
|
|
41
|
+
* message is sent only if the context was accepted; `bestEffort: true` sends it regardless.
|
|
42
|
+
* Never rejects. A result of `appended` is a prompt delivered, not an action taken.
|
|
43
|
+
*/
|
|
44
|
+
appendMessage(
|
|
45
|
+
text: string,
|
|
46
|
+
options?: {
|
|
47
|
+
/** The only accepted value; the person's role is what hosts permit a view to speak as. */
|
|
48
|
+
readonly role?: 'user';
|
|
49
|
+
readonly context?: {
|
|
50
|
+
readonly text: string;
|
|
51
|
+
readonly data?: Record<string, unknown>;
|
|
52
|
+
/** Send the message even when the context could not be delivered. Default `false`. */
|
|
53
|
+
readonly bestEffort?: boolean;
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
): Promise<AppendResult>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* For a page that has no host at all: every call resolves `unavailable` and nothing is sent. The
|
|
61
|
+
* stage is the first request the call would have made: the context, unless it is best effort.
|
|
62
|
+
*/
|
|
63
|
+
export const NO_CONVERSATION: Conversation = Object.freeze<Conversation>({
|
|
64
|
+
appendMessage: (_text, options) => {
|
|
65
|
+
const context = options?.context;
|
|
66
|
+
return Promise.resolve<AppendResult>({
|
|
67
|
+
outcome: 'unavailable',
|
|
68
|
+
stage:
|
|
69
|
+
context !== undefined && context.bestEffort !== true
|
|
70
|
+
? 'context'
|
|
71
|
+
: 'message',
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
});
|