@tangle-network/agent-interface 5.10.2 → 5.10.4

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 CHANGED
@@ -5,6 +5,12 @@ agents, the sidecar, and provider adapters: capabilities, agent profiles,
5
5
  message parts, and harness descriptors. This is the canonical home for those
6
6
  shapes; higher-level packages import from here rather than redefining them.
7
7
 
8
+ `partitionBySpeaker` and its `Speaker`, `SpeakerPart`, `SpeakerState` and
9
+ `SpeakerSection` types are available from the root and the server-safe `/speaker`
10
+ entry. Stored parts follow their preceding speaker; explicit live `speaker` tags
11
+ win over position. Repeated headers update the same section, unowned parts come
12
+ first, and input objects retain their identity. UI chat re-exports this contract.
13
+
8
14
  ## Authored subscription seats
9
15
 
10
16
  `AgentProfile.seats` is an optional ordered chain for continuing one logical agent
@@ -7,7 +7,7 @@ import type { AgentProfile, AgentProfileCapabilities, AgentProfileValidationResu
7
7
  import type { InputPart } from "./parts.js";
8
8
  import type { StreamEvent } from "./stream-events.js";
9
9
  import { type TokenUsage } from "./execution-types.js";
10
- import { type InteractionAcknowledgement, type InteractionCapabilities, type InteractionResponseCommand, type RequestedInteractions } from "./interaction.js";
10
+ import { type InteractionAcknowledgement, type InteractionCapabilities, type InteractionResponseCommand, type InteractionStateReader, type RequestedInteractions } from "./interaction.js";
11
11
  import { type ContextTransferReceipt, type ContextTransferRequest, type ContextTransferResult, type NativeContextBoundaryProof, type NativeContextContinuationRequest, type NativeContextContinuationTurn } from "./portable-context.js";
12
12
  import { type AgentExactRunControlRef, type AgentRunCancellationAcknowledgement, type AgentRunCancellationRequest, type AgentRunControlRef } from "./runtime-control.js";
13
13
  import type { AgentWorkspaceBranching, AgentWorkspaceBranchingProvider } from "./workspace-branching.js";
@@ -1280,7 +1280,7 @@ export interface AgentEnvironmentEvent {
1280
1280
  usageMode?: "delta" | "cumulative";
1281
1281
  providerEvent?: unknown;
1282
1282
  }
1283
- export interface AgentSession {
1283
+ export interface AgentSession extends InteractionStateReader {
1284
1284
  readonly id: string;
1285
1285
  readonly controlRef?: AgentRunControlRef;
1286
1286
  status(options?: {
package/dist/index.d.ts CHANGED
@@ -47,3 +47,4 @@ export { AgentEnvironmentEgressPolicySchema } from "./environment-requests.js";
47
47
  export * from "./native-session-event.js";
48
48
  export * from "./learning-state.js";
49
49
  export * from "./proxy-secrets.js";
50
+ export * from "./speaker.js";
package/dist/index.js CHANGED
@@ -49,3 +49,4 @@ export { AgentEnvironmentEgressPolicySchema } from "./environment-requests.js";
49
49
  export * from "./native-session-event.js";
50
50
  export * from "./learning-state.js";
51
51
  export * from "./proxy-secrets.js";
52
+ export * from "./speaker.js";
@@ -0,0 +1,203 @@
1
+ import { z } from "zod";
2
+ /** Delivery is independent of recording a response; only delivered proves its native effect. */
3
+ export declare const InteractionResolutionDeliveryStateSchema: z.ZodEnum<{
4
+ pending: "pending";
5
+ delivering: "delivering";
6
+ delivered: "delivered";
7
+ delivery_failed: "delivery_failed";
8
+ backend_lost: "backend_lost";
9
+ effect_unknown: "effect_unknown";
10
+ }>;
11
+ export type InteractionResolutionDeliveryState = z.infer<typeof InteractionResolutionDeliveryStateSchema>;
12
+ /** Durable resolution metadata, including legacy records without an exact binding. */
13
+ export declare const InteractionResolutionAcknowledgementSchema: z.ZodObject<{
14
+ status: z.ZodEnum<{
15
+ accepted: "accepted";
16
+ already_resolved_same: "already_resolved_same";
17
+ }>;
18
+ operationId: z.ZodString;
19
+ responseDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
20
+ interactionId: z.ZodString;
21
+ sessionId: z.ZodString;
22
+ outcome: z.ZodEnum<{
23
+ cancelled: "cancelled";
24
+ accepted: "accepted";
25
+ declined: "declined";
26
+ }>;
27
+ deliveryState: z.ZodEnum<{
28
+ pending: "pending";
29
+ delivering: "delivering";
30
+ delivered: "delivered";
31
+ delivery_failed: "delivery_failed";
32
+ backend_lost: "backend_lost";
33
+ effect_unknown: "effect_unknown";
34
+ }>;
35
+ delivered: z.ZodBoolean;
36
+ resolvedAt: z.ZodString;
37
+ binding: z.ZodOptional<z.ZodObject<{
38
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
39
+ runId: z.ZodString;
40
+ provider: z.ZodString;
41
+ environmentId: z.ZodString;
42
+ sessionId: z.ZodString;
43
+ executionId: z.ZodString;
44
+ interactionId: z.ZodString;
45
+ }, z.core.$strict>>;
46
+ }, z.core.$strict>;
47
+ export type InteractionResolutionAcknowledgement = z.infer<typeof InteractionResolutionAcknowledgementSchema>;
48
+ /** Owner truth at one read; an absent owner and an empty outstanding set are different facts. */
49
+ export declare const InteractionSnapshotSchema: z.ZodObject<{
50
+ availability: z.ZodEnum<{
51
+ unavailable: "unavailable";
52
+ available: "available";
53
+ missing: "missing";
54
+ }>;
55
+ sessionId: z.ZodString;
56
+ executionId: z.ZodOptional<z.ZodString>;
57
+ interactions: z.ZodArray<z.ZodObject<{
58
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
59
+ id: z.ZodString;
60
+ kind: z.ZodString;
61
+ title: z.ZodString;
62
+ body: z.ZodOptional<z.ZodString>;
63
+ subject: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
64
+ type: z.ZodLiteral<"tool">;
65
+ toolName: z.ZodString;
66
+ input: z.ZodOptional<z.ZodCustom<unknown, unknown>>;
67
+ }, z.core.$strict>, z.ZodObject<{
68
+ type: z.ZodLiteral<"command">;
69
+ command: z.ZodString;
70
+ }, z.core.$strict>, z.ZodObject<{
71
+ type: z.ZodLiteral<"file">;
72
+ path: z.ZodString;
73
+ preview: z.ZodOptional<z.ZodString>;
74
+ }, z.core.$strict>, z.ZodObject<{
75
+ type: z.ZodLiteral<"resource">;
76
+ uri: z.ZodString;
77
+ }, z.core.$strict>], "type">>;
78
+ answerSpec: z.ZodObject<{
79
+ fields: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
80
+ type: z.ZodLiteral<"text">;
81
+ multiline: z.ZodOptional<z.ZodBoolean>;
82
+ placeholder: z.ZodOptional<z.ZodString>;
83
+ maxLength: z.ZodOptional<z.ZodNumber>;
84
+ default: z.ZodOptional<z.ZodString>;
85
+ name: z.ZodString;
86
+ label: z.ZodString;
87
+ required: z.ZodOptional<z.ZodBoolean>;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ type: z.ZodLiteral<"number">;
90
+ min: z.ZodOptional<z.ZodNumber>;
91
+ max: z.ZodOptional<z.ZodNumber>;
92
+ default: z.ZodOptional<z.ZodNumber>;
93
+ name: z.ZodString;
94
+ label: z.ZodString;
95
+ required: z.ZodOptional<z.ZodBoolean>;
96
+ }, z.core.$strict>, z.ZodObject<{
97
+ type: z.ZodLiteral<"boolean">;
98
+ default: z.ZodOptional<z.ZodBoolean>;
99
+ name: z.ZodString;
100
+ label: z.ZodString;
101
+ required: z.ZodOptional<z.ZodBoolean>;
102
+ }, z.core.$strict>, z.ZodObject<{
103
+ type: z.ZodLiteral<"select">;
104
+ options: z.ZodArray<z.ZodObject<{
105
+ value: z.ZodString;
106
+ label: z.ZodString;
107
+ description: z.ZodOptional<z.ZodString>;
108
+ }, z.core.$strict>>;
109
+ multi: z.ZodOptional<z.ZodBoolean>;
110
+ allowCustom: z.ZodOptional<z.ZodBoolean>;
111
+ default: z.ZodOptional<z.ZodArray<z.ZodString>>;
112
+ name: z.ZodString;
113
+ label: z.ZodString;
114
+ required: z.ZodOptional<z.ZodBoolean>;
115
+ }, z.core.$strict>, z.ZodObject<{
116
+ type: z.ZodLiteral<"secret">;
117
+ placeholder: z.ZodOptional<z.ZodString>;
118
+ maxLength: z.ZodOptional<z.ZodNumber>;
119
+ name: z.ZodString;
120
+ label: z.ZodString;
121
+ required: z.ZodOptional<z.ZodBoolean>;
122
+ }, z.core.$strict>], "type">>;
123
+ }, z.core.$strict>;
124
+ responseScopes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
125
+ interaction: "interaction";
126
+ session: "session";
127
+ persistent: "persistent";
128
+ }>>>;
129
+ allowedOutcomes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
130
+ cancelled: "cancelled";
131
+ accepted: "accepted";
132
+ declined: "declined";
133
+ }>>>;
134
+ default: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
135
+ outcome: z.ZodLiteral<"accepted">;
136
+ data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
137
+ }, z.core.$strict>, z.ZodObject<{
138
+ outcome: z.ZodLiteral<"declined">;
139
+ data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
140
+ }, z.core.$strict>, z.ZodObject<{
141
+ outcome: z.ZodLiteral<"cancelled">;
142
+ data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
143
+ }, z.core.$strict>], "outcome">>;
144
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
145
+ onTimeout: z.ZodOptional<z.ZodEnum<{
146
+ default: "default";
147
+ fail: "fail";
148
+ wait: "wait";
149
+ }>>;
150
+ binding: z.ZodObject<{
151
+ runId: z.ZodString;
152
+ provider: z.ZodString;
153
+ environmentId: z.ZodString;
154
+ sessionId: z.ZodString;
155
+ executionId: z.ZodString;
156
+ interactionId: z.ZodString;
157
+ }, z.core.$strict>;
158
+ }, z.core.$strict>>;
159
+ resolutions: z.ZodArray<z.ZodObject<{
160
+ status: z.ZodEnum<{
161
+ accepted: "accepted";
162
+ already_resolved_same: "already_resolved_same";
163
+ }>;
164
+ operationId: z.ZodString;
165
+ responseDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
166
+ interactionId: z.ZodString;
167
+ sessionId: z.ZodString;
168
+ outcome: z.ZodEnum<{
169
+ cancelled: "cancelled";
170
+ accepted: "accepted";
171
+ declined: "declined";
172
+ }>;
173
+ deliveryState: z.ZodEnum<{
174
+ pending: "pending";
175
+ delivering: "delivering";
176
+ delivered: "delivered";
177
+ delivery_failed: "delivery_failed";
178
+ backend_lost: "backend_lost";
179
+ effect_unknown: "effect_unknown";
180
+ }>;
181
+ delivered: z.ZodBoolean;
182
+ resolvedAt: z.ZodString;
183
+ binding: z.ZodOptional<z.ZodObject<{
184
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
185
+ runId: z.ZodString;
186
+ provider: z.ZodString;
187
+ environmentId: z.ZodString;
188
+ sessionId: z.ZodString;
189
+ executionId: z.ZodString;
190
+ interactionId: z.ZodString;
191
+ }, z.core.$strict>>;
192
+ }, z.core.$strict>>;
193
+ }, z.core.$strict>;
194
+ export type InteractionSnapshot = z.infer<typeof InteractionSnapshotSchema>;
195
+ export interface InteractionReadOptions {
196
+ state: true;
197
+ executionId?: string;
198
+ signal?: AbortSignal;
199
+ }
200
+ /** Optional owner-read capability; existing session implementations remain valid. */
201
+ export interface InteractionStateReader {
202
+ interactions?(options: InteractionReadOptions): Promise<InteractionSnapshot>;
203
+ }
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ import { sha256DigestSchema } from "./agent-candidate-schema-common.js";
3
+ import { CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
4
+ import { InteractionBindingSchema, InteractionRequestSchema } from "./interaction-envelope.js";
5
+ /** Delivery is independent of recording a response; only delivered proves its native effect. */
6
+ export const InteractionResolutionDeliveryStateSchema = z.enum([
7
+ "pending", "delivering", "delivered", "delivery_failed", "backend_lost", "effect_unknown",
8
+ ]);
9
+ /** Durable resolution metadata, including legacy records without an exact binding. */
10
+ export const InteractionResolutionAcknowledgementSchema = z.strictObject({
11
+ status: z.enum(["accepted", "already_resolved_same"]),
12
+ operationId: z.string().min(1),
13
+ responseDigest: sha256DigestSchema,
14
+ interactionId: z.string().min(1),
15
+ sessionId: z.string().min(1),
16
+ outcome: z.enum(["accepted", "declined", "cancelled"]),
17
+ deliveryState: InteractionResolutionDeliveryStateSchema,
18
+ delivered: z.boolean(),
19
+ resolvedAt: z.string().min(1),
20
+ binding: InteractionBindingSchema.optional(),
21
+ });
22
+ /** Owner truth at one read; an absent owner and an empty outstanding set are different facts. */
23
+ export const InteractionSnapshotSchema = z.strictObject({
24
+ availability: z.enum(["available", "missing", "unavailable"]),
25
+ sessionId: InteractionBindingSchema.shape.sessionId,
26
+ executionId: InteractionBindingSchema.shape.executionId.optional(),
27
+ interactions: z.array(InteractionRequestSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
28
+ resolutions: z.array(InteractionResolutionAcknowledgementSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
29
+ });
@@ -4,3 +4,4 @@ export * from "./interaction-envelope.js";
4
4
  export * from "./interaction-permissions.js";
5
5
  export * from "./interaction-answer-validation.js";
6
6
  export * from "./interaction-response-validation.js";
7
+ export * from "./interaction-state.js";
@@ -4,3 +4,4 @@ export * from "./interaction-envelope.js";
4
4
  export * from "./interaction-permissions.js";
5
5
  export * from "./interaction-answer-validation.js";
6
6
  export * from "./interaction-response-validation.js";
7
+ export * from "./interaction-state.js";
@@ -0,0 +1,41 @@
1
+ /** Where one responder is in its answer. */
2
+ export type SpeakerState = "answering" | "done" | "failed";
3
+ /**
4
+ * A responder of a turn addressed to several agents. In the turn's parts it is
5
+ * a `{ type: "speaker", id, name, handle?, state? }` part written before the
6
+ * responder's answer.
7
+ */
8
+ export interface Speaker {
9
+ /** The agent's stable id. It keys the avatar's tone and a live part's `speaker` tag. */
10
+ id: string;
11
+ name: string;
12
+ /** What a person types after `@` to address the agent. */
13
+ handle?: string;
14
+ /** Set once the responder ended; absent while it answers and on rows written before responders reported an end. */
15
+ state?: SpeakerState;
16
+ }
17
+ export type SpeakerPart = Speaker & {
18
+ type: "speaker";
19
+ };
20
+ /** One responder's share of a turn: its speaker part and the parts it wrote. */
21
+ export interface SpeakerSection<T> {
22
+ /** The latest speaker part for this responder; null for the parts no speaker owns. */
23
+ speaker: (T & SpeakerPart) | null;
24
+ parts: T[];
25
+ }
26
+ /**
27
+ * Splits one assistant turn's parts by the agent that wrote them.
28
+ *
29
+ * A stored row holds a speaker part before each responder's answer, so a part
30
+ * belongs to the speaker part before it. A live stream announces every
31
+ * responder first and then interleaves their output, so a part names its owner
32
+ * in `speaker` (the responder's id), which wins over position. A later speaker
33
+ * part with an id already seen replaces that responder's speaker part, which is
34
+ * how its end state arrives, and never opens a second section.
35
+ *
36
+ * Sections keep the order speakers were first announced. Parts no speaker owns
37
+ * come first, in a section whose `speaker` is null; a turn without speaker
38
+ * parts is that one section. No part is dropped, copied or reordered within its
39
+ * section.
40
+ */
41
+ export declare function partitionBySpeaker<T extends object>(parts: readonly T[]): SpeakerSection<T>[];
@@ -0,0 +1,39 @@
1
+ function isSpeakerPart(part) {
2
+ const record = part;
3
+ return !!record && record.type === "speaker" && typeof record.id === "string" && typeof record.name === "string";
4
+ }
5
+ /**
6
+ * Splits one assistant turn's parts by the agent that wrote them.
7
+ *
8
+ * A stored row holds a speaker part before each responder's answer, so a part
9
+ * belongs to the speaker part before it. A live stream announces every
10
+ * responder first and then interleaves their output, so a part names its owner
11
+ * in `speaker` (the responder's id), which wins over position. A later speaker
12
+ * part with an id already seen replaces that responder's speaker part, which is
13
+ * how its end state arrives, and never opens a second section.
14
+ *
15
+ * Sections keep the order speakers were first announced. Parts no speaker owns
16
+ * come first, in a section whose `speaker` is null; a turn without speaker
17
+ * parts is that one section. No part is dropped, copied or reordered within its
18
+ * section.
19
+ */
20
+ export function partitionBySpeaker(parts) {
21
+ const sections = new Map();
22
+ const unowned = [];
23
+ let current;
24
+ for (const part of parts) {
25
+ if (isSpeakerPart(part)) {
26
+ current = sections.get(part.id);
27
+ if (current)
28
+ current.speaker = part;
29
+ else
30
+ sections.set(part.id, (current = { speaker: part, parts: [] }));
31
+ continue;
32
+ }
33
+ const tag = part.speaker;
34
+ const owner = typeof tag === "string" ? sections.get(tag) : current;
35
+ (owner?.parts ?? unowned).push(part);
36
+ }
37
+ const owned = [...sections.values()];
38
+ return unowned.length > 0 || owned.length === 0 ? [{ speaker: null, parts: unowned }, ...owned] : owned;
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "5.10.2",
3
+ "version": "5.10.4",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -66,6 +66,11 @@
66
66
  "import": "./dist/learning-state.js",
67
67
  "types": "./dist/learning-state.d.ts",
68
68
  "default": "./dist/learning-state.js"
69
+ },
70
+ "./speaker": {
71
+ "import": "./dist/speaker.js",
72
+ "types": "./dist/speaker.d.ts",
73
+ "default": "./dist/speaker.js"
69
74
  }
70
75
  },
71
76
  "repository": {