@xenosystem/agent-interface-host 0.1.151 → 0.1.152

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.
@@ -0,0 +1,28 @@
1
+ import type { AgentConversationTranscriptItem, AgentRuntimeEventDraft, AgentRuntimeEventEnvelope, AgentTurnMessage, AgentTurnStartRequest } from '@xenosystem/agent-interface-contract';
2
+ /**
3
+ * The host owns the conversation (decision 0001, ADE §9 step 5).
4
+ *
5
+ * The transcript is a PROJECTION of the host's own append-only event log, never a second store: the lanes already
6
+ * write the reply, tools and usage there, and the host adds the one thing only it saw — what the person said — as a
7
+ * `turn.input` event before it dispatches the turn. A second transcript store beside the log would be a second record
8
+ * that could disagree with the first.
9
+ */
10
+ export declare const TURN_INPUT_EVENT_TYPE = "turn.input";
11
+ /**
12
+ * The draft the host appends before dispatching a turn. `redact` is the workspace's own redaction, the same one every
13
+ * persisted lane event passes through, so a secret typed into a prompt is stored exactly as a secret in a reply is.
14
+ */
15
+ export declare function turnInputEventDraft(request: AgentTurnStartRequest, provider: {
16
+ id: string;
17
+ kind: string;
18
+ }, redact?: (value: Record<string, unknown>) => Record<string, unknown>): AgentRuntimeEventDraft;
19
+ export declare function projectHostTranscript(events: readonly AgentRuntimeEventEnvelope[], options?: {
20
+ subagentRunId?: string;
21
+ }): AgentConversationTranscriptItem[];
22
+ /**
23
+ * The history a `historySource: 'host'` turn is sent with: every earlier turn of the thread, the person's words and
24
+ * the reply the model actually produced. A turn still running is not history. A reply with no text (a turn that only
25
+ * ran tools, or failed before speaking) contributes nothing rather than an empty message.
26
+ */
27
+ export declare function hostHistoryFromTranscript(items: readonly AgentConversationTranscriptItem[], currentRequestId: string): AgentTurnMessage[];
28
+ //# sourceMappingURL=hostTranscript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostTranscript.d.ts","sourceRoot":"","sources":["../../src/transcript/hostTranscript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,+BAA+B,EAC/B,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,sCAAsC,CAAA;AAG7C;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,eAAe,CAAA;AAEjD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACtC,MAAM,GAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAoB,GACrF,sBAAsB,CAsBxB;AAUD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,yBAAyB,EAAE,EAC5C,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAO,GACvC,+BAA+B,EAAE,CAoDnC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,SAAS,+BAA+B,EAAE,EAAE,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,EAAE,CASzI"}
@@ -0,0 +1,124 @@
1
+ import { projectRuntimeTimeline } from '../runtime/RuntimeTimelineProjection.js';
2
+ /**
3
+ * The host owns the conversation (decision 0001, ADE §9 step 5).
4
+ *
5
+ * The transcript is a PROJECTION of the host's own append-only event log, never a second store: the lanes already
6
+ * write the reply, tools and usage there, and the host adds the one thing only it saw — what the person said — as a
7
+ * `turn.input` event before it dispatches the turn. A second transcript store beside the log would be a second record
8
+ * that could disagree with the first.
9
+ */
10
+ export const TURN_INPUT_EVENT_TYPE = 'turn.input';
11
+ /**
12
+ * The draft the host appends before dispatching a turn. `redact` is the workspace's own redaction, the same one every
13
+ * persisted lane event passes through, so a secret typed into a prompt is stored exactly as a secret in a reply is.
14
+ */
15
+ export function turnInputEventDraft(request, provider, redact = (value) => value) {
16
+ const event = redact({
17
+ // One per request: a replayed or retried dispatch of the same request lands on the same id and is a duplicate.
18
+ id: `turn-input-${request.requestId}`,
19
+ type: TURN_INPUT_EVENT_TYPE,
20
+ timestamp: new Date().toISOString(),
21
+ text: request.prompt,
22
+ });
23
+ return {
24
+ conversationId: request.conversationId,
25
+ requestId: request.requestId,
26
+ ...(request.workspaceId ? { workspaceId: request.workspaceId } : {}),
27
+ ...(request.teamId ? { teamId: request.teamId } : {}),
28
+ ...(request.agentId ? { agentId: request.agentId } : {}),
29
+ ...(request.subagentRunId ? { subagentRunId: request.subagentRunId } : {}),
30
+ providerKind: provider.kind,
31
+ providerId: provider.id,
32
+ source: 'agent-host',
33
+ schemaVersion: '1',
34
+ redactionState: 'safe',
35
+ event,
36
+ };
37
+ }
38
+ /**
39
+ * One thread of the log: the conversation's own turns, or one subagent run's. A child run writes under its parent's
40
+ * conversation id with its own `subagentRunId`, and is not part of the parent's transcript.
41
+ */
42
+ function inThread(event, subagentRunId) {
43
+ return (event.subagentRunId || undefined) === (subagentRunId || undefined);
44
+ }
45
+ export function projectHostTranscript(events, options = {}) {
46
+ const thread = events.filter((event) => inThread(event, options.subagentRunId));
47
+ const inputs = new Map();
48
+ const answered = new Set();
49
+ for (const event of thread) {
50
+ if (event.type === TURN_INPUT_EVENT_TYPE) {
51
+ if (!inputs.has(event.requestId))
52
+ inputs.set(event.requestId, event);
53
+ }
54
+ else
55
+ answered.add(event.requestId);
56
+ }
57
+ const timeline = projectRuntimeTimeline(thread.filter((event) => event.type !== TURN_INPUT_EVENT_TYPE));
58
+ const requests = new Map(timeline.requests.map((request) => [request.requestId, request]));
59
+ const toolsByRequest = new Map();
60
+ for (const tool of timeline.tools) {
61
+ const list = toolsByRequest.get(tool.requestId) ?? [];
62
+ list.push({ id: tool.id, toolName: tool.toolName, status: tool.status });
63
+ toolsByRequest.set(tool.requestId, list);
64
+ }
65
+ // Ordered by where each turn starts in the log: its input when the host recorded one, else its first lane event
66
+ // (turns from before decision 0001 have no input event, and their replies still belong in order).
67
+ const firstSequence = new Map();
68
+ for (const event of thread)
69
+ if (!firstSequence.has(event.requestId))
70
+ firstSequence.set(event.requestId, event.sequence);
71
+ const order = [...firstSequence.keys()].sort((a, b) => firstSequence.get(a) - firstSequence.get(b));
72
+ const items = [];
73
+ for (const requestId of order) {
74
+ const input = inputs.get(requestId);
75
+ if (input) {
76
+ items.push({
77
+ kind: 'user',
78
+ itemId: input.id,
79
+ requestId,
80
+ sequence: input.sequence,
81
+ timestamp: input.timestamp,
82
+ text: typeof input.event.text === 'string' ? input.event.text : '',
83
+ });
84
+ }
85
+ const reply = requests.get(requestId);
86
+ if (!answered.has(requestId) || !reply)
87
+ continue;
88
+ items.push({
89
+ kind: 'assistant',
90
+ itemId: `reply-${requestId}`,
91
+ requestId,
92
+ status: reply.status,
93
+ text: reply.text,
94
+ ...(reply.model ? { model: reply.model } : {}),
95
+ ...(reply.completedAt || reply.failedAt ? { completedAt: (reply.completedAt || reply.failedAt) } : {}),
96
+ ...(reply.error ? { error: reply.error } : {}),
97
+ tools: toolsByRequest.get(requestId) ?? [],
98
+ ...(reply.tokenUsage ? { tokenUsage: { ...reply.tokenUsage } } : {}),
99
+ });
100
+ }
101
+ return items;
102
+ }
103
+ /**
104
+ * The history a `historySource: 'host'` turn is sent with: every earlier turn of the thread, the person's words and
105
+ * the reply the model actually produced. A turn still running is not history. A reply with no text (a turn that only
106
+ * ran tools, or failed before speaking) contributes nothing rather than an empty message.
107
+ */
108
+ export function hostHistoryFromTranscript(items, currentRequestId) {
109
+ const history = [];
110
+ for (const item of items) {
111
+ if (item.requestId === currentRequestId)
112
+ continue;
113
+ if (item.kind === 'user') {
114
+ history.push({ role: 'user', content: item.text });
115
+ continue;
116
+ }
117
+ if (item.status === 'running')
118
+ continue;
119
+ if (item.text.trim())
120
+ history.push({ role: 'assistant', content: item.text });
121
+ }
122
+ return history;
123
+ }
124
+ //# sourceMappingURL=hostTranscript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostTranscript.js","sourceRo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;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAiD,EAAE,gBAAwB;IACnH,MAAM,OAAO,GAAuB,EAAE,CAAA;IACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,SAAS,KAAK,gBAAgB;YAAE,SAAQ;QACjD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAAC,SAAQ;QAAC,CAAC;QAC1F,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,SAAQ;QACvC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IAC/E,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xenosystem/agent-interface-host",
3
- "version": "0.1.151",
3
+ "version": "0.1.152",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -37,13 +37,13 @@
37
37
  "@xenosystem/capability-sdk": "0.1.1",
38
38
  "@xenosystem/primitives": "0.3.1",
39
39
  "zod": "4.6.7",
40
- "@xenosystem/agent-interface-contract": "0.1.151",
41
- "@xenosystem/agent-interface-core": "0.1.151",
42
- "@xenosystem/capability-mcp": "0.1.151"
40
+ "@xenosystem/capability-mcp": "0.1.152",
41
+ "@xenosystem/agent-interface-core": "0.1.152",
42
+ "@xenosystem/agent-interface-contract": "0.1.152"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "@xenosystem/acp-agent": "0.2.25",
46
- "@xenosystem/agent-interface-client": "0.1.151"
46
+ "@xenosystem/agent-interface-client": "0.1.152"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@xeno-corporation/account": "0.4.1",
@@ -66,8 +66,7 @@
66
66
  "better-sqlite3": "13.0.3",
67
67
  "node-pty": "^1.1.0",
68
68
  "fflate": "^0.8.3",
69
- "@xenosystem/agent-interface-client": "0.1.151"
69
+ "@xenosystem/agent-interface-client": "0.1.152"
70
70
  },
71
- "scripts": {},
72
- "gitHead": "b832bd3f32c339888b9b1a7a9cd6a5ea52e491c2"
71
+ "scripts": {}
73
72
  }