omk-agent-core 0.97.0 → 0.98.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.
Files changed (67) hide show
  1. package/README.md +4 -4
  2. package/dist/agent-loop.d.ts.map +1 -1
  3. package/dist/agent-loop.js +35 -31
  4. package/dist/agent-loop.js.map +1 -1
  5. package/dist/agent.d.ts.map +1 -1
  6. package/dist/agent.js +1 -1
  7. package/dist/agent.js.map +1 -1
  8. package/dist/harness/agent-harness.d.ts +9 -8
  9. package/dist/harness/agent-harness.d.ts.map +1 -1
  10. package/dist/harness/agent-harness.js +145 -182
  11. package/dist/harness/agent-harness.js.map +1 -1
  12. package/dist/harness/compaction/branch-summarization.d.ts +5 -1
  13. package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  14. package/dist/harness/compaction/branch-summarization.js +3 -3
  15. package/dist/harness/compaction/branch-summarization.js.map +1 -1
  16. package/dist/harness/compaction/compaction.d.ts +8 -4
  17. package/dist/harness/compaction/compaction.d.ts.map +1 -1
  18. package/dist/harness/compaction/compaction.js +28 -118
  19. package/dist/harness/compaction/compaction.js.map +1 -1
  20. package/dist/harness/compaction/operation.d.ts +6 -0
  21. package/dist/harness/compaction/operation.d.ts.map +1 -0
  22. package/dist/harness/compaction/operation.js +2 -0
  23. package/dist/harness/compaction/operation.js.map +1 -0
  24. package/dist/harness/compaction/summarization-prompts.d.ts +5 -0
  25. package/dist/harness/compaction/summarization-prompts.d.ts.map +1 -0
  26. package/dist/harness/compaction/summarization-prompts.js +88 -0
  27. package/dist/harness/compaction/summarization-prompts.js.map +1 -0
  28. package/dist/harness/errors.d.ts +15 -0
  29. package/dist/harness/errors.d.ts.map +1 -0
  30. package/dist/harness/errors.js +32 -0
  31. package/dist/harness/errors.js.map +1 -0
  32. package/dist/harness/harness-session.d.ts +105 -0
  33. package/dist/harness/harness-session.d.ts.map +1 -0
  34. package/dist/harness/harness-session.js +116 -0
  35. package/dist/harness/harness-session.js.map +1 -0
  36. package/dist/harness/messages.d.ts +3 -1
  37. package/dist/harness/messages.d.ts.map +1 -1
  38. package/dist/harness/messages.js +26 -0
  39. package/dist/harness/messages.js.map +1 -1
  40. package/dist/harness/name-validation.d.ts +2 -0
  41. package/dist/harness/name-validation.d.ts.map +1 -0
  42. package/dist/harness/name-validation.js +11 -0
  43. package/dist/harness/name-validation.js.map +1 -0
  44. package/dist/harness/stream-options.d.ts +31 -0
  45. package/dist/harness/stream-options.d.ts.map +1 -0
  46. package/dist/harness/stream-options.js +66 -0
  47. package/dist/harness/stream-options.js.map +1 -0
  48. package/dist/harness/summarization-retry.d.ts +29 -0
  49. package/dist/harness/summarization-retry.d.ts.map +1 -0
  50. package/dist/harness/summarization-retry.js +20 -0
  51. package/dist/harness/summarization-retry.js.map +1 -0
  52. package/dist/harness/types.d.ts +36 -41
  53. package/dist/harness/types.d.ts.map +1 -1
  54. package/dist/harness/types.js +1 -32
  55. package/dist/harness/types.js.map +1 -1
  56. package/dist/tool-resource-claims.d.ts +1 -1
  57. package/dist/tool-resource-claims.d.ts.map +1 -1
  58. package/dist/tool-resource-claims.js +1 -1
  59. package/dist/tool-resource-claims.js.map +1 -1
  60. package/dist/tool-timeout-settlement.d.ts +6 -0
  61. package/dist/tool-timeout-settlement.d.ts.map +1 -0
  62. package/dist/tool-timeout-settlement.js +11 -0
  63. package/dist/tool-timeout-settlement.js.map +1 -0
  64. package/dist/types.d.ts +9 -10
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/types.js.map +1 -1
  67. package/package.json +2 -2
@@ -0,0 +1,116 @@
1
+ import { createImmutableSnapshot } from "../plain-data.js";
2
+ import { AgentHarnessError, toError } from "./errors.js";
3
+ /**
4
+ * Internal implementation of the public `HarnessSession` structural interface.
5
+ *
6
+ * This module intentionally imports no harness/session types. `AgentHarness` and the
7
+ * raw session are in a legacy import-cycle component; importing their types here would
8
+ * pull this new boundary into that component because the cycle ratchet treats static
9
+ * type imports as architectural edges. Generic ports keep the implementation a leaf.
10
+ */
11
+ export class HarnessSessionFacade {
12
+ session;
13
+ getPhase;
14
+ pendingWrites;
15
+ constructor(session, getPhase, pendingWrites) {
16
+ this.session = session;
17
+ this.getPhase = getPhase;
18
+ this.pendingWrites = pendingWrites;
19
+ }
20
+ async getMetadata() {
21
+ return this.read(() => this.session.getMetadata());
22
+ }
23
+ async getLeafId() {
24
+ return this.read(() => this.session.getLeafId());
25
+ }
26
+ async getEntry(id) {
27
+ return this.read(() => this.session.getEntry(id));
28
+ }
29
+ async getEntries() {
30
+ return this.read(() => this.session.getEntries());
31
+ }
32
+ async getBranch(fromId) {
33
+ return this.read(() => this.session.getBranch(fromId));
34
+ }
35
+ async buildContext() {
36
+ return this.read(() => this.session.buildContext());
37
+ }
38
+ async getLabel(id) {
39
+ return this.read(() => this.session.getLabel(id));
40
+ }
41
+ async getSessionName() {
42
+ return this.read(() => this.session.getSessionName());
43
+ }
44
+ getPendingWrites() {
45
+ return createImmutableSnapshot(this.pendingWrites);
46
+ }
47
+ async appendMessage(message) {
48
+ const write = this.snapshot({ type: "message", message });
49
+ await this.write(write, () => this.session.appendMessage(write.message));
50
+ }
51
+ async appendCustomEntry(customType, data) {
52
+ const write = this.snapshot({ type: "custom", customType, data });
53
+ await this.write(write, () => this.session.appendCustomEntry(write.customType, write.data));
54
+ }
55
+ async appendCustomMessage(input) {
56
+ const write = this.snapshot({
57
+ type: "custom_message",
58
+ customType: input.customType,
59
+ content: typeof input.content === "string" ? input.content : [...input.content],
60
+ display: input.display,
61
+ details: input.details,
62
+ });
63
+ await this.write(write, () => this.session.appendCustomMessageEntry(write.customType, write.content, write.display, write.details));
64
+ }
65
+ async appendLabel(targetId, label) {
66
+ if (!(await this.getEntry(targetId))) {
67
+ throw new AgentHarnessError("invalid_argument", `Entry ${targetId} not found`);
68
+ }
69
+ const write = this.snapshot({ type: "label", targetId, label });
70
+ await this.write(write, () => this.session.appendLabel(write.targetId, write.label));
71
+ }
72
+ async appendSessionName(name) {
73
+ const write = this.snapshot({ type: "session_info", name: name.trim() });
74
+ await this.write(write, () => this.session.appendSessionName(write.name ?? ""));
75
+ }
76
+ async setLeafId(targetId) {
77
+ if (targetId !== null && !(await this.getEntry(targetId))) {
78
+ throw new AgentHarnessError("invalid_argument", `Entry ${targetId} not found`);
79
+ }
80
+ const write = this.snapshot({ type: "leaf", targetId });
81
+ await this.write(write, () => this.session.moveTo(write.targetId));
82
+ }
83
+ async read(operation) {
84
+ try {
85
+ return createImmutableSnapshot(await operation());
86
+ }
87
+ catch (error) {
88
+ throw new AgentHarnessError("session", "Session read failed", toError(error));
89
+ }
90
+ }
91
+ snapshot(write) {
92
+ try {
93
+ return createImmutableSnapshot(write);
94
+ }
95
+ catch (error) {
96
+ throw new AgentHarnessError("invalid_argument", "Session writes must contain plain data", toError(error));
97
+ }
98
+ }
99
+ async write(write, persist) {
100
+ const phase = this.getPhase();
101
+ if (phase === "turn") {
102
+ this.pendingWrites.push(write);
103
+ return;
104
+ }
105
+ if (phase !== "idle") {
106
+ throw new AgentHarnessError("invalid_state", `Cannot write session state during ${phase}`);
107
+ }
108
+ try {
109
+ await persist();
110
+ }
111
+ catch (error) {
112
+ throw new AgentHarnessError("session", "Session write failed", toError(error));
113
+ }
114
+ }
115
+ }
116
+ //# sourceMappingURL=harness-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-session.js","sourceRoot":"","sources":["../../src/harness/harness-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAkEzD;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAoB;IACf,OAAO,CAAqD;IAC5D,QAAQ,CAAe;IACvB,aAAa,CAA2B;IAEzD,YACC,OAA2D,EAC3D,QAAsB,EACtB,aAAuC,EACtC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ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AAC,CAAC;QAC5F,CAAC;QACD,IAAI,CAAC;YACJ,MAAM,OAAO,EAAE,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAiB,CAAC,SAAS,EAAE,sBAAsB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAChF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { ImageContent, TextContent } from \"omk-ai\";\nimport { createImmutableSnapshot } from \"../plain-data.ts\";\nimport { AgentHarnessError, toError } from \"./errors.ts\";\n\ntype FacadeWrite<TMessage> =\n\t| { readonly type: \"message\"; readonly message: TMessage }\n\t| { readonly type: \"custom\"; readonly customType: string; readonly data?: unknown }\n\t| {\n\t\t\treadonly type: \"custom_message\";\n\t\t\treadonly customType: string;\n\t\t\treadonly content: string | (TextContent | ImageContent)[];\n\t\t\treadonly details?: unknown;\n\t\t\treadonly display: boolean;\n\t }\n\t| { readonly type: \"label\"; readonly targetId: string; readonly label: string | undefined }\n\t| { readonly type: \"session_info\"; readonly name?: string }\n\t| { readonly type: \"leaf\"; readonly targetId: string | null };\n\ntype PendingWrite<TMessage> =\n\t| FacadeWrite<TMessage>\n\t| { readonly type: \"thinking_level_change\"; readonly thinkingLevel: string }\n\t| { readonly type: \"model_change\"; readonly provider: string; readonly modelId: string }\n\t| { readonly type: \"active_tools_change\"; readonly activeToolNames: string[] }\n\t| {\n\t\t\treadonly type: \"compaction\";\n\t\t\treadonly summary: string;\n\t\t\treadonly firstKeptEntryId: string;\n\t\t\treadonly tokensBefore: number;\n\t\t\treadonly details?: unknown;\n\t\t\treadonly fromHook?: boolean;\n\t }\n\t| {\n\t\t\treadonly type: \"branch_summary\";\n\t\t\treadonly fromId: string;\n\t\t\treadonly summary: string;\n\t\t\treadonly details?: unknown;\n\t\t\treadonly fromHook?: boolean;\n\t };\n\ninterface SessionPort<TMessage, TEntry, TContext, TMetadata> {\n\tgetMetadata(): Promise<TMetadata>;\n\tgetLeafId(): Promise<string | null>;\n\tgetEntry(id: string): Promise<TEntry | undefined>;\n\tgetEntries(): Promise<TEntry[]>;\n\tgetBranch(fromId?: string): Promise<TEntry[]>;\n\tbuildContext(): Promise<TContext>;\n\tgetLabel(id: string): Promise<string | undefined>;\n\tgetSessionName(): Promise<string | undefined>;\n\tappendMessage(message: TMessage): Promise<string>;\n\tappendCustomEntry(customType: string, data?: unknown): Promise<string>;\n\tappendCustomMessageEntry(\n\t\tcustomType: string,\n\t\tcontent: string | (TextContent | ImageContent)[],\n\t\tdisplay: boolean,\n\t\tdetails?: unknown,\n\t): Promise<string>;\n\tappendLabel(targetId: string, label: string | undefined): Promise<string>;\n\tappendSessionName(name: string): Promise<string>;\n\tmoveTo(entryId: string | null): Promise<string | undefined>;\n}\n\ninterface CustomMessageInput<T = unknown> {\n\treadonly customType: string;\n\treadonly content: string | readonly (TextContent | ImageContent)[];\n\treadonly display: boolean;\n\treadonly details?: T;\n}\n\n/**\n * Internal implementation of the public `HarnessSession` structural interface.\n *\n * This module intentionally imports no harness/session types. `AgentHarness` and the\n * raw session are in a legacy import-cycle component; importing their types here would\n * pull this new boundary into that component because the cycle ratchet treats static\n * type imports as architectural edges. Generic ports keep the implementation a leaf.\n */\nexport class HarnessSessionFacade<TMessage, TEntry, TContext, TMetadata> {\n\tprivate readonly session: SessionPort<TMessage, TEntry, TContext, TMetadata>;\n\tprivate readonly getPhase: () => string;\n\tprivate readonly pendingWrites: PendingWrite<TMessage>[];\n\n\tconstructor(\n\t\tsession: SessionPort<TMessage, TEntry, TContext, TMetadata>,\n\t\tgetPhase: () => string,\n\t\tpendingWrites: PendingWrite<TMessage>[],\n\t) {\n\t\tthis.session = session;\n\t\tthis.getPhase = getPhase;\n\t\tthis.pendingWrites = pendingWrites;\n\t}\n\n\tasync getMetadata(): Promise<Readonly<TMetadata>> {\n\t\treturn this.read(() => this.session.getMetadata());\n\t}\n\n\tasync getLeafId(): Promise<string | null> {\n\t\treturn this.read(() => this.session.getLeafId());\n\t}\n\n\tasync getEntry(id: string): Promise<Readonly<TEntry> | undefined> {\n\t\treturn this.read(() => this.session.getEntry(id));\n\t}\n\n\tasync getEntries(): Promise<readonly Readonly<TEntry>[]> {\n\t\treturn this.read(() => this.session.getEntries());\n\t}\n\n\tasync getBranch(fromId?: string): Promise<readonly Readonly<TEntry>[]> {\n\t\treturn this.read(() => this.session.getBranch(fromId));\n\t}\n\n\tasync buildContext(): Promise<Readonly<TContext>> {\n\t\treturn this.read(() => this.session.buildContext());\n\t}\n\n\tasync getLabel(id: string): Promise<string | undefined> {\n\t\treturn this.read(() => this.session.getLabel(id));\n\t}\n\n\tasync getSessionName(): Promise<string | undefined> {\n\t\treturn this.read(() => this.session.getSessionName());\n\t}\n\n\tgetPendingWrites(): readonly PendingWrite<TMessage>[] {\n\t\treturn createImmutableSnapshot(this.pendingWrites);\n\t}\n\n\tasync appendMessage(message: TMessage): Promise<void> {\n\t\tconst write = this.snapshot({ type: \"message\", message });\n\t\tawait this.write(write, () => this.session.appendMessage(write.message));\n\t}\n\n\tasync appendCustomEntry(customType: string, data?: unknown): Promise<void> {\n\t\tconst write = this.snapshot({ type: \"custom\", customType, data });\n\t\tawait this.write(write, () => this.session.appendCustomEntry(write.customType, write.data));\n\t}\n\n\tasync appendCustomMessage<T = unknown>(input: CustomMessageInput<T>): Promise<void> {\n\t\tconst write = this.snapshot({\n\t\t\ttype: \"custom_message\",\n\t\t\tcustomType: input.customType,\n\t\t\tcontent: typeof input.content === \"string\" ? input.content : [...input.content],\n\t\t\tdisplay: input.display,\n\t\t\tdetails: input.details,\n\t\t});\n\t\tawait this.write(write, () =>\n\t\t\tthis.session.appendCustomMessageEntry(write.customType, write.content, write.display, write.details),\n\t\t);\n\t}\n\n\tasync appendLabel(targetId: string, label: string | undefined): Promise<void> {\n\t\tif (!(await this.getEntry(targetId))) {\n\t\t\tthrow new AgentHarnessError(\"invalid_argument\", `Entry ${targetId} not found`);\n\t\t}\n\t\tconst write = this.snapshot({ type: \"label\", targetId, label });\n\t\tawait this.write(write, () => this.session.appendLabel(write.targetId, write.label));\n\t}\n\n\tasync appendSessionName(name: string): Promise<void> {\n\t\tconst write = this.snapshot({ type: \"session_info\", name: name.trim() });\n\t\tawait this.write(write, () => this.session.appendSessionName(write.name ?? \"\"));\n\t}\n\n\tasync setLeafId(targetId: string | null): Promise<void> {\n\t\tif (targetId !== null && !(await this.getEntry(targetId))) {\n\t\t\tthrow new AgentHarnessError(\"invalid_argument\", `Entry ${targetId} not found`);\n\t\t}\n\t\tconst write = this.snapshot({ type: \"leaf\", targetId });\n\t\tawait this.write(write, () => this.session.moveTo(write.targetId));\n\t}\n\n\tprivate async read<T>(operation: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\treturn createImmutableSnapshot(await operation());\n\t\t} catch (error) {\n\t\t\tthrow new AgentHarnessError(\"session\", \"Session read failed\", toError(error));\n\t\t}\n\t}\n\n\tprivate snapshot<TWrite extends FacadeWrite<TMessage>>(write: TWrite): TWrite {\n\t\ttry {\n\t\t\treturn createImmutableSnapshot(write);\n\t\t} catch (error) {\n\t\t\tthrow new AgentHarnessError(\"invalid_argument\", \"Session writes must contain plain data\", toError(error));\n\t\t}\n\t}\n\n\tprivate async write(write: FacadeWrite<TMessage>, persist: () => Promise<unknown>): Promise<void> {\n\t\tconst phase = this.getPhase();\n\t\tif (phase === \"turn\") {\n\t\t\tthis.pendingWrites.push(write);\n\t\t\treturn;\n\t\t}\n\t\tif (phase !== \"idle\") {\n\t\t\tthrow new AgentHarnessError(\"invalid_state\", `Cannot write session state during ${phase}`);\n\t\t}\n\t\ttry {\n\t\t\tawait persist();\n\t\t} catch (error) {\n\t\t\tthrow new AgentHarnessError(\"session\", \"Session write failed\", toError(error));\n\t\t}\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ImageContent, Message, TextContent } from "omk-ai";
1
+ import type { AssistantMessage, ImageContent, Message, Model, TextContent, UserMessage } from "omk-ai";
2
2
  import type { AgentMessage } from "../types.ts";
3
3
  export declare const COMPACTION_SUMMARY_PREFIX = "The conversation history before this point was compacted into the following summary:\n\n<summary>\n";
4
4
  export declare const COMPACTION_SUMMARY_SUFFIX = "\n</summary>";
@@ -43,6 +43,8 @@ declare module "../types.ts" {
43
43
  compactionSummary: CompactionSummaryMessage;
44
44
  }
45
45
  }
46
+ export declare function createUserMessage(text: string, images?: ImageContent[]): UserMessage;
47
+ export declare function createFailureMessage(model: Model<any>, error: unknown, aborted: boolean): AssistantMessage;
46
48
  export declare function bashExecutionToText(msg: BashExecutionMessage): string;
47
49
  export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage;
48
50
  export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string): CompactionSummaryMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,yBAAyB,wGAGrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,iBAC3B,CAAC;AAEZ,eAAO,MAAM,qBAAqB,iGAGjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;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AAM,GACf,aAAa,CASf;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CA4ChE","sourcesContent":["import type { ImageContent, Message, TextContent } from \"omk-ai\";\nimport type { AgentMessage } from \"../types.ts\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.ts\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n}\n"]}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACvG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,yBAAyB,wGAGrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,iBAC3B,CAAC;AAEZ,eAAO,MAAM,qBAAqB,iGAGjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,C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,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAmB1G;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM,CAgBrE;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,oBAAoB,CAOnH;AAED,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GACf,wBAAwB,CAO1B;AAED,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,EAChD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GACf,aAAa,CASf;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CA4ChE","sourcesContent":["import type { AssistantMessage, ImageContent, Message, Model, TextContent, UserMessage } from \"omk-ai\";\nimport type { AgentMessage } from \"../types.ts\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.ts\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function createUserMessage(text: string, images?: ImageContent[]): UserMessage {\n\tconst content: Array<{ type: \"text\"; text: string } | ImageContent> = [{ type: \"text\", text }];\n\tif (images) content.push(...images);\n\treturn { role: \"user\", content, timestamp: Date.now() };\n}\n\nexport function createFailureMessage(model: Model<any>, error: unknown, aborted: boolean): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [{ type: \"text\", text: \"\" }],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tstopReason: aborted ? \"aborted\" : \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t};\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n}\n"]}
@@ -9,6 +9,32 @@ export const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch tha
9
9
  <summary>
10
10
  `;
11
11
  export const BRANCH_SUMMARY_SUFFIX = `</summary>`;
12
+ export function createUserMessage(text, images) {
13
+ const content = [{ type: "text", text }];
14
+ if (images)
15
+ content.push(...images);
16
+ return { role: "user", content, timestamp: Date.now() };
17
+ }
18
+ export function createFailureMessage(model, error, aborted) {
19
+ return {
20
+ role: "assistant",
21
+ content: [{ type: "text", text: "" }],
22
+ api: model.api,
23
+ provider: model.provider,
24
+ model: model.id,
25
+ stopReason: aborted ? "aborted" : "error",
26
+ errorMessage: error instanceof Error ? error.message : String(error),
27
+ timestamp: Date.now(),
28
+ usage: {
29
+ input: 0,
30
+ output: 0,
31
+ cacheRead: 0,
32
+ cacheWrite: 0,
33
+ totalTokens: 0,
34
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
35
+ },
36
+ };
37
+ }
12
38
  export function bashExecutionToText(msg) {
13
39
  let text = `Ran \`${msg.command}\`\n`;
14
40
  if (msg.output) {
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;CAGxC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG;WAC9B,CAAC;AAEZ,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;CAGpC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AA8ClD,MAAM,UAAU,mBAAmB,CAAC,GAAyB,EAAU;IACtE,IAAI,IAAI,GAAG,SAAS,GAAG,CAAC,OAAO,MAAM,CAAC;IACtC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,IAAI,WAAW,GAAG,CAAC,MAAM,UAAU,CAAC;IACzC,CAAC;SAAM,CAAC;QACP,IAAI,IAAI,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QACnB,IAAI,IAAI,yBAAyB,CAAC;IACnC,CAAC;SAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACtF,IAAI,IAAI,gCAAgC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxD,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;QACzC,IAAI,IAAI,uCAAuC,GAAG,CAAC,cAAc,GAAG,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAe,EAAE,MAAc,EAAE,SAAiB,EAAwB;IACpH,OAAO;QACN,IAAI,EAAE,eAAe;QACrB,OAAO;QACP,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CAAC,CAAC,OAAO,CAAC;gBACzG,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO;oBACP,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,CAAC;YACD,KAAK,eAAe;gBACnB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,qBAAqB,EAAE,CAAC;oBACrG,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,mBAAmB;gBACvB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACR,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,yBAAyB,GAAG,CAAC,CAAC,OAAO,GAAG,yBAAyB,EAAE;qBAClG;oBACD,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,MAAM,CAAC;YACZ,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV;gBACC,OAAO,SAAS,CAAC;QACnB,CAAC;IAAA,CACD,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AAAA,CAC/C","sourcesContent":["import type { ImageContent, Message, TextContent } from \"omk-ai\";\nimport type { AgentMessage } from \"../types.ts\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.ts\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n}\n"]}
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;CAGxC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG;WAC9B,CAAC;AAEZ,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;CAGpC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AA8ClD,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,MAAuB,EAAe;IACrF,MAAM,OAAO,GAAyD,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/F,IAAI,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;IACpC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAAA,CACxD;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAiB,EAAE,KAAc,EAAE,OAAgB,EAAoB;IAC3G,OAAO;QACN,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QACrC,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,O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E,MAAe,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzG,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO;oBACP,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,CAAC;YACD,KAAK,eAAe;gBACnB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,qBAAqB,EAAE,CAAC;oBACrG,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,mBAAmB;gBACvB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACR,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,yBAAyB,GAAG,CAAC,CAAC,OAAO,GAAG,yBAAyB,EAAE;qBAClG;oBACD,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,MAAM,CAAC;YACZ,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV;gBACC,OAAO,SAAS,CAAC;QACnB,CAAC;IAAA,CACD,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AAAA,CAC/C","sourcesContent":["import type { AssistantMessage, ImageContent, Message, Model, TextContent, UserMessage } from \"omk-ai\";\nimport type { AgentMessage } from \"../types.ts\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.ts\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function createUserMessage(text: string, images?: ImageContent[]): UserMessage {\n\tconst content: Array<{ type: \"text\"; text: string } | ImageContent> = [{ type: \"text\", text }];\n\tif (images) content.push(...images);\n\treturn { role: \"user\", content, timestamp: Date.now() };\n}\n\nexport function createFailureMessage(model: Model<any>, error: unknown, aborted: boolean): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [{ type: \"text\", text: \"\" }],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tstopReason: aborted ? \"aborted\" : \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t};\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function findDuplicateNames(names: readonly string[]): string[];
2
+ //# sourceMappingURL=name-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-validation.d.ts","sourceRoot":"","sources":["../../src/harness/name-validation.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAQrE","sourcesContent":["export function findDuplicateNames(names: readonly string[]): string[] {\n\tconst seen = new Set<string>();\n\tconst duplicates = new Set<string>();\n\tfor (const name of names) {\n\t\tif (seen.has(name)) duplicates.add(name);\n\t\tseen.add(name);\n\t}\n\treturn [...duplicates];\n}\n"]}
@@ -0,0 +1,11 @@
1
+ export function findDuplicateNames(names) {
2
+ const seen = new Set();
3
+ const duplicates = new Set();
4
+ for (const name of names) {
5
+ if (seen.has(name))
6
+ duplicates.add(name);
7
+ seen.add(name);
8
+ }
9
+ return [...duplicates];
10
+ }
11
+ //# sourceMappingURL=name-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-validation.js","sourceRoot":"","sources":["../../src/harness/name-validation.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,KAAwB,EAAY;IACtE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC;AAAA,CACvB","sourcesContent":["export function findDuplicateNames(names: readonly string[]): string[] {\n\tconst seen = new Set<string>();\n\tconst duplicates = new Set<string>();\n\tfor (const name of names) {\n\t\tif (seen.has(name)) duplicates.add(name);\n\t\tseen.add(name);\n\t}\n\treturn [...duplicates];\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { RetryPolicy, SimpleStreamOptions, Transport } from "omk-ai";
2
+ /** Curated provider request options owned by the harness and snapshotted per turn. */
3
+ export interface AgentHarnessStreamOptions {
4
+ /** Preferred transport forwarded to the stream function. */
5
+ transport?: Transport;
6
+ /** Provider request timeout in milliseconds. */
7
+ timeoutMs?: number;
8
+ /** Maximum provider retry attempts. */
9
+ maxRetries?: number;
10
+ /** Optional cap for provider-requested retry delays. */
11
+ maxRetryDelayMs?: number;
12
+ /** Additional request headers merged with auth and lifecycle headers. */
13
+ headers?: Record<string, string>;
14
+ /** Provider metadata forwarded with requests. */
15
+ metadata?: SimpleStreamOptions["metadata"];
16
+ /** Provider cache retention hint. */
17
+ cacheRetention?: SimpleStreamOptions["cacheRetention"];
18
+ /** Retry policy for generated compaction and branch-summary requests. */
19
+ summarizationRetry?: RetryPolicy;
20
+ }
21
+ /** Per-request stream option patch returned by provider hooks. */
22
+ export interface AgentHarnessStreamOptionsPatch extends Omit<Partial<AgentHarnessStreamOptions>, "headers" | "metadata" | "summarizationRetry"> {
23
+ /** Header patch. `undefined` values delete keys; explicit `headers: undefined` clears all headers. */
24
+ headers?: Record<string, string | undefined>;
25
+ /** Metadata patch. `undefined` values delete keys; explicit `metadata: undefined` clears all metadata. */
26
+ metadata?: Record<string, unknown | undefined>;
27
+ }
28
+ export declare function cloneStreamOptions(streamOptions?: AgentHarnessStreamOptions): AgentHarnessStreamOptions;
29
+ export declare function mergeHeaders(...headers: Array<Record<string, string> | undefined>): Record<string, string> | undefined;
30
+ export declare function applyStreamOptionsPatch(base: AgentHarnessStreamOptions, patch?: AgentHarnessStreamOptionsPatch): AgentHarnessStreamOptions;
31
+ //# sourceMappingURL=stream-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-options.d.ts","sourceRoot":"","sources":["../../src/harness/stream-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE1E,sFAAsF;AACtF,MAAM,WAAW,yBAAyB;IACzC,4DAA4D;IAC5D,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC3C,qCAAqC;IACrC,cAAc,CAAC,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACvD,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,WAAW,CAAC;CACjC;AAED,kEAAkE;AAClE,MAAM,WAAW,8BAChB,SAAQ,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,oBAAoB,CAAC;IAC/F,sGAAsG;IACtG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;CAC/C;AAED,wBAAgB,kBAAkB,CAAC,aAAa,CAAC,EAAE,yBAAyB,GAAG,yBAAyB,CAOvG;AAED,wBAAgB,YAAY,CAC3B,GAAG,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,GACnD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CASpC;AAED,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,yBAAyB,EAC/B,KAAK,CAAC,EAAE,8BAA8B,GACpC,yBAAyB,CAqC3B","sourcesContent":["import type { RetryPolicy, SimpleStreamOptions, Transport } from \"omk-ai\";\n\n/** Curated provider request options owned by the harness and snapshotted per turn. */\nexport interface AgentHarnessStreamOptions {\n\t/** Preferred transport forwarded to the stream function. */\n\ttransport?: Transport;\n\t/** Provider request timeout in milliseconds. */\n\ttimeoutMs?: number;\n\t/** Maximum provider retry attempts. */\n\tmaxRetries?: number;\n\t/** Optional cap for provider-requested retry delays. */\n\tmaxRetryDelayMs?: number;\n\t/** Additional request headers merged with auth and lifecycle headers. */\n\theaders?: Record<string, string>;\n\t/** Provider metadata forwarded with requests. */\n\tmetadata?: SimpleStreamOptions[\"metadata\"];\n\t/** Provider cache retention hint. */\n\tcacheRetention?: SimpleStreamOptions[\"cacheRetention\"];\n\t/** Retry policy for generated compaction and branch-summary requests. */\n\tsummarizationRetry?: RetryPolicy;\n}\n\n/** Per-request stream option patch returned by provider hooks. */\nexport interface AgentHarnessStreamOptionsPatch\n\textends Omit<Partial<AgentHarnessStreamOptions>, \"headers\" | \"metadata\" | \"summarizationRetry\"> {\n\t/** Header patch. `undefined` values delete keys; explicit `headers: undefined` clears all headers. */\n\theaders?: Record<string, string | undefined>;\n\t/** Metadata patch. `undefined` values delete keys; explicit `metadata: undefined` clears all metadata. */\n\tmetadata?: Record<string, unknown | undefined>;\n}\n\nexport function cloneStreamOptions(streamOptions?: AgentHarnessStreamOptions): AgentHarnessStreamOptions {\n\treturn {\n\t\t...streamOptions,\n\t\theaders: streamOptions?.headers ? { ...streamOptions.headers } : undefined,\n\t\tmetadata: streamOptions?.metadata ? { ...streamOptions.metadata } : undefined,\n\t\tsummarizationRetry: streamOptions?.summarizationRetry ? { ...streamOptions.summarizationRetry } : undefined,\n\t};\n}\n\nexport function mergeHeaders(\n\t...headers: Array<Record<string, string> | undefined>\n): Record<string, string> | undefined {\n\tconst merged: Record<string, string> = {};\n\tlet hasHeaders = false;\n\tfor (const entry of headers) {\n\t\tif (!entry) continue;\n\t\tObject.assign(merged, entry);\n\t\thasHeaders = true;\n\t}\n\treturn hasHeaders ? merged : undefined;\n}\n\nexport function applyStreamOptionsPatch(\n\tbase: AgentHarnessStreamOptions,\n\tpatch?: AgentHarnessStreamOptionsPatch,\n): AgentHarnessStreamOptions {\n\tconst result = cloneStreamOptions(base);\n\tif (!patch) return result;\n\n\tif (Object.hasOwn(patch, \"transport\")) result.transport = patch.transport;\n\tif (Object.hasOwn(patch, \"timeoutMs\")) result.timeoutMs = patch.timeoutMs;\n\tif (Object.hasOwn(patch, \"maxRetries\")) result.maxRetries = patch.maxRetries;\n\tif (Object.hasOwn(patch, \"maxRetryDelayMs\")) result.maxRetryDelayMs = patch.maxRetryDelayMs;\n\tif (Object.hasOwn(patch, \"cacheRetention\")) result.cacheRetention = patch.cacheRetention;\n\n\tif (Object.hasOwn(patch, \"headers\")) {\n\t\tif (patch.headers === undefined) {\n\t\t\tresult.headers = undefined;\n\t\t} else {\n\t\t\tconst headers = { ...(result.headers ?? {}) };\n\t\t\tfor (const [key, value] of Object.entries(patch.headers)) {\n\t\t\t\tif (value === undefined) delete headers[key];\n\t\t\t\telse headers[key] = value;\n\t\t\t}\n\t\t\tresult.headers = Object.keys(headers).length > 0 ? headers : undefined;\n\t\t}\n\t}\n\n\tif (Object.hasOwn(patch, \"metadata\")) {\n\t\tif (patch.metadata === undefined) {\n\t\t\tresult.metadata = undefined;\n\t\t} else {\n\t\t\tconst metadata = { ...(result.metadata ?? {}) };\n\t\t\tfor (const [key, value] of Object.entries(patch.metadata)) {\n\t\t\t\tif (value === undefined) delete metadata[key];\n\t\t\t\telse metadata[key] = value;\n\t\t\t}\n\t\t\tresult.metadata = Object.keys(metadata).length > 0 ? metadata : undefined;\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
@@ -0,0 +1,66 @@
1
+ export function cloneStreamOptions(streamOptions) {
2
+ return {
3
+ ...streamOptions,
4
+ headers: streamOptions?.headers ? { ...streamOptions.headers } : undefined,
5
+ metadata: streamOptions?.metadata ? { ...streamOptions.metadata } : undefined,
6
+ summarizationRetry: streamOptions?.summarizationRetry ? { ...streamOptions.summarizationRetry } : undefined,
7
+ };
8
+ }
9
+ export function mergeHeaders(...headers) {
10
+ const merged = {};
11
+ let hasHeaders = false;
12
+ for (const entry of headers) {
13
+ if (!entry)
14
+ continue;
15
+ Object.assign(merged, entry);
16
+ hasHeaders = true;
17
+ }
18
+ return hasHeaders ? merged : undefined;
19
+ }
20
+ export function applyStreamOptionsPatch(base, patch) {
21
+ const result = cloneStreamOptions(base);
22
+ if (!patch)
23
+ return result;
24
+ if (Object.hasOwn(patch, "transport"))
25
+ result.transport = patch.transport;
26
+ if (Object.hasOwn(patch, "timeoutMs"))
27
+ result.timeoutMs = patch.timeoutMs;
28
+ if (Object.hasOwn(patch, "maxRetries"))
29
+ result.maxRetries = patch.maxRetries;
30
+ if (Object.hasOwn(patch, "maxRetryDelayMs"))
31
+ result.maxRetryDelayMs = patch.maxRetryDelayMs;
32
+ if (Object.hasOwn(patch, "cacheRetention"))
33
+ result.cacheRetention = patch.cacheRetention;
34
+ if (Object.hasOwn(patch, "headers")) {
35
+ if (patch.headers === undefined) {
36
+ result.headers = undefined;
37
+ }
38
+ else {
39
+ const headers = { ...(result.headers ?? {}) };
40
+ for (const [key, value] of Object.entries(patch.headers)) {
41
+ if (value === undefined)
42
+ delete headers[key];
43
+ else
44
+ headers[key] = value;
45
+ }
46
+ result.headers = Object.keys(headers).length > 0 ? headers : undefined;
47
+ }
48
+ }
49
+ if (Object.hasOwn(patch, "metadata")) {
50
+ if (patch.metadata === undefined) {
51
+ result.metadata = undefined;
52
+ }
53
+ else {
54
+ const metadata = { ...(result.metadata ?? {}) };
55
+ for (const [key, value] of Object.entries(patch.metadata)) {
56
+ if (value === undefined)
57
+ delete metadata[key];
58
+ else
59
+ metadata[key] = value;
60
+ }
61
+ result.metadata = Object.keys(metadata).length > 0 ? metadata : undefined;
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ //# sourceMappingURL=stream-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-options.js","sourceRoot":"","sources":["../../src/harness/stream-options.ts"],"names":[],"mappings":"AA+BA,MAAM,UAAU,kBAAkB,CAAC,aAAyC,EAA6B;IACxG,OAAO;QACN,GAAG,aAAa;QAChB,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,G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MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC3D,IAAI,KAAK,KAAK,SAAS;oBAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;;oBACzC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC5B,CAAC;YACD,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import type { RetryPolicy, SimpleStreamOptions, Transport } from \"omk-ai\";\n\n/** Curated provider request options owned by the harness and snapshotted per turn. */\nexport interface AgentHarnessStreamOptions {\n\t/** Preferred transport forwarded to the stream function. */\n\ttransport?: Transport;\n\t/** Provider request timeout in milliseconds. */\n\ttimeoutMs?: number;\n\t/** Maximum provider retry attempts. */\n\tmaxRetries?: number;\n\t/** Optional cap for provider-requested retry delays. */\n\tmaxRetryDelayMs?: number;\n\t/** Additional request headers merged with auth and lifecycle headers. */\n\theaders?: Record<string, string>;\n\t/** Provider metadata forwarded with requests. */\n\tmetadata?: SimpleStreamOptions[\"metadata\"];\n\t/** Provider cache retention hint. */\n\tcacheRetention?: SimpleStreamOptions[\"cacheRetention\"];\n\t/** Retry policy for generated compaction and branch-summary requests. */\n\tsummarizationRetry?: RetryPolicy;\n}\n\n/** Per-request stream option patch returned by provider hooks. */\nexport interface AgentHarnessStreamOptionsPatch\n\textends Omit<Partial<AgentHarnessStreamOptions>, \"headers\" | \"metadata\" | \"summarizationRetry\"> {\n\t/** Header patch. `undefined` values delete keys; explicit `headers: undefined` clears all headers. */\n\theaders?: Record<string, string | undefined>;\n\t/** Metadata patch. `undefined` values delete keys; explicit `metadata: undefined` clears all metadata. */\n\tmetadata?: Record<string, unknown | undefined>;\n}\n\nexport function cloneStreamOptions(streamOptions?: AgentHarnessStreamOptions): AgentHarnessStreamOptions {\n\treturn {\n\t\t...streamOptions,\n\t\theaders: streamOptions?.headers ? { ...streamOptions.headers } : undefined,\n\t\tmetadata: streamOptions?.metadata ? { ...streamOptions.metadata } : undefined,\n\t\tsummarizationRetry: streamOptions?.summarizationRetry ? { ...streamOptions.summarizationRetry } : undefined,\n\t};\n}\n\nexport function mergeHeaders(\n\t...headers: Array<Record<string, string> | undefined>\n): Record<string, string> | undefined {\n\tconst merged: Record<string, string> = {};\n\tlet hasHeaders = false;\n\tfor (const entry of headers) {\n\t\tif (!entry) continue;\n\t\tObject.assign(merged, entry);\n\t\thasHeaders = true;\n\t}\n\treturn hasHeaders ? merged : undefined;\n}\n\nexport function applyStreamOptionsPatch(\n\tbase: AgentHarnessStreamOptions,\n\tpatch?: AgentHarnessStreamOptionsPatch,\n): AgentHarnessStreamOptions {\n\tconst result = cloneStreamOptions(base);\n\tif (!patch) return result;\n\n\tif (Object.hasOwn(patch, \"transport\")) result.transport = patch.transport;\n\tif (Object.hasOwn(patch, \"timeoutMs\")) result.timeoutMs = patch.timeoutMs;\n\tif (Object.hasOwn(patch, \"maxRetries\")) result.maxRetries = patch.maxRetries;\n\tif (Object.hasOwn(patch, \"maxRetryDelayMs\")) result.maxRetryDelayMs = patch.maxRetryDelayMs;\n\tif (Object.hasOwn(patch, \"cacheRetention\")) result.cacheRetention = patch.cacheRetention;\n\n\tif (Object.hasOwn(patch, \"headers\")) {\n\t\tif (patch.headers === undefined) {\n\t\t\tresult.headers = undefined;\n\t\t} else {\n\t\t\tconst headers = { ...(result.headers ?? {}) };\n\t\t\tfor (const [key, value] of Object.entries(patch.headers)) {\n\t\t\t\tif (value === undefined) delete headers[key];\n\t\t\t\telse headers[key] = value;\n\t\t\t}\n\t\t\tresult.headers = Object.keys(headers).length > 0 ? headers : undefined;\n\t\t}\n\t}\n\n\tif (Object.hasOwn(patch, \"metadata\")) {\n\t\tif (patch.metadata === undefined) {\n\t\t\tresult.metadata = undefined;\n\t\t} else {\n\t\t\tconst metadata = { ...(result.metadata ?? {}) };\n\t\t\tfor (const [key, value] of Object.entries(patch.metadata)) {\n\t\t\t\tif (value === undefined) delete metadata[key];\n\t\t\t\telse metadata[key] = value;\n\t\t\t}\n\t\t\tresult.metadata = Object.keys(metadata).length > 0 ? metadata : undefined;\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import type { RetryCallbacks, RetryPolicy } from "omk-ai";
2
+ export type SummarizationOperation = "compaction" | "branch_summary";
3
+ export interface RetryScheduledEvent {
4
+ readonly type: "retry_scheduled";
5
+ readonly operation: SummarizationOperation;
6
+ readonly attempt: number;
7
+ readonly maxAttempts: number;
8
+ readonly delayMs: number;
9
+ readonly errorMessage: string;
10
+ }
11
+ export interface RetryAttemptStartEvent {
12
+ readonly type: "retry_attempt_start";
13
+ readonly operation: SummarizationOperation;
14
+ readonly attempt: number;
15
+ }
16
+ export interface RetryFinishedEvent {
17
+ readonly type: "retry_finished";
18
+ readonly operation: SummarizationOperation;
19
+ readonly success: boolean;
20
+ readonly attempt: number;
21
+ readonly finalError?: string;
22
+ }
23
+ export type SummarizationRetryEvent = RetryScheduledEvent | RetryAttemptStartEvent | RetryFinishedEvent;
24
+ /** Build retry policy/callbacks without coupling the leaf module to harness event types. */
25
+ export declare function createSummarizationRetry(operation: SummarizationOperation, policy: RetryPolicy | undefined, emit: (event: SummarizationRetryEvent) => Promise<void> | void): {
26
+ readonly retry: RetryPolicy | undefined;
27
+ readonly callbacks: RetryCallbacks;
28
+ };
29
+ //# sourceMappingURL=summarization-retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarization-retry.d.ts","sourceRoot":"","sources":["../../src/harness/summarization-retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1D,M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"compaction\" | \"branch_summary\";\n\nexport interface RetryScheduledEvent {\n\treadonly type: \"retry_scheduled\";\n\treadonly operation: SummarizationOperation;\n\treadonly attempt: number;\n\treadonly maxAttempts: number;\n\treadonly delayMs: number;\n\treadonly errorMessage: string;\n}\n\nexport interface RetryAttemptStartEvent {\n\treadonly type: \"retry_attempt_start\";\n\treadonly operation: SummarizationOperation;\n\treadonly attempt: number;\n}\n\nexport interface RetryFinishedEvent {\n\treadonly type: \"retry_finished\";\n\treadonly operation: SummarizationOperation;\n\treadonly success: boolean;\n\treadonly attempt: number;\n\treadonly finalError?: string;\n}\n\nexport type SummarizationRetryEvent = RetryScheduledEvent | RetryAttemptStartEvent | RetryFinishedEvent;\n\n/** Build retry policy/callbacks without coupling the leaf module to harness event types. */\nexport function createSummarizationRetry(\n\toperation: SummarizationOperation,\n\tpolicy: RetryPolicy | undefined,\n\temit: (event: SummarizationRetryEvent) => Promise<void> | void,\n): { readonly retry: RetryPolicy | undefined; readonly callbacks: RetryCallbacks } {\n\tlet scheduledAttempt = 0;\n\treturn {\n\t\tretry: policy,\n\t\tcallbacks: {\n\t\t\tonRetryScheduled: async (attempt, maxAttempts, delayMs, errorMessage) => {\n\t\t\t\tscheduledAttempt = attempt;\n\t\t\t\tawait emit({ type: \"retry_scheduled\", operation, attempt, maxAttempts, delayMs, errorMessage });\n\t\t\t},\n\t\t\tonRetryAttemptStart: async () => {\n\t\t\t\tawait emit({ type: \"retry_attempt_start\", operation, attempt: scheduledAttempt });\n\t\t\t},\n\t\t\tonRetryFinished: async (success, attempt, finalError) => {\n\t\t\t\tawait emit({ type: \"retry_finished\", operation, success, attempt, finalError });\n\t\t\t},\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /** Build retry policy/callbacks without coupling the leaf module to harness event types. */
2
+ export function createSummarizationRetry(operation, policy, emit) {
3
+ let scheduledAttempt = 0;
4
+ return {
5
+ retry: policy,
6
+ callbacks: {
7
+ onRetryScheduled: async (attempt, maxAttempts, delayMs, errorMessage) => {
8
+ scheduledAttempt = attempt;
9
+ await emit({ type: "retry_scheduled", operation, attempt, maxAttempts, delayMs, errorMessage });
10
+ },
11
+ onRetryAttemptStart: async () => {
12
+ await emit({ type: "retry_attempt_start", operation, attempt: scheduledAttempt });
13
+ },
14
+ onRetryFinished: async (success, attempt, finalError) => {
15
+ await emit({ type: "retry_finished", operation, success, attempt, finalError });
16
+ },
17
+ },
18
+ };
19
+ }
20
+ //# sourceMappingURL=summarization-retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarization-retry.js","sourceRoot":"","sources":["../../src/harness/summarization-retry.ts"],"names":[],"mappings":"AA6BA,4FAA4F;AAC5F,MAAM,UAAU,wBAAwB,CACvC,SAAiC,EACjC,MAA+B,EAC/B,IAA8D,EACoB;IAClF,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,OAAO;QACN,KAAK,EAAE,MAAM;QACb,SAAS,EAAE;YACV,gBAAgB,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,CAAC;gBACxE,gBAAgB,GAAG,OAAO,CAAC;gBAC3B,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;YAAA,CAChG;YACD,mBAAmB,EAAE,KAAK,IAAI,EAAE,CAAC;gBAChC,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;YAAA,CAClF;YACD,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC;gBACxD,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;YAAA,CAChF;SACD;KACD,CAAC;AAAA,CACF","sourcesContent":["import type { RetryCallbacks, RetryPolicy } from \"omk-ai\";\n\nexport type SummarizationOperation = \"compaction\" | \"branch_summary\";\n\nexport interface RetryScheduledEvent {\n\treadonly type: \"retry_scheduled\";\n\treadonly operation: SummarizationOperation;\n\treadonly attempt: number;\n\treadonly maxAttempts: number;\n\treadonly delayMs: number;\n\treadonly errorMessage: string;\n}\n\nexport interface RetryAttemptStartEvent {\n\treadonly type: \"retry_attempt_start\";\n\treadonly operation: SummarizationOperation;\n\treadonly attempt: number;\n}\n\nexport interface RetryFinishedEvent {\n\treadonly type: \"retry_finished\";\n\treadonly operation: SummarizationOperation;\n\treadonly success: boolean;\n\treadonly attempt: number;\n\treadonly finalError?: string;\n}\n\nexport type SummarizationRetryEvent = RetryScheduledEvent | RetryAttemptStartEvent | RetryFinishedEvent;\n\n/** Build retry policy/callbacks without coupling the leaf module to harness event types. */\nexport function createSummarizationRetry(\n\toperation: SummarizationOperation,\n\tpolicy: RetryPolicy | undefined,\n\temit: (event: SummarizationRetryEvent) => Promise<void> | void,\n): { readonly retry: RetryPolicy | undefined; readonly callbacks: RetryCallbacks } {\n\tlet scheduledAttempt = 0;\n\treturn {\n\t\tretry: policy,\n\t\tcallbacks: {\n\t\t\tonRetryScheduled: async (attempt, maxAttempts, delayMs, errorMessage) => {\n\t\t\t\tscheduledAttempt = attempt;\n\t\t\t\tawait emit({ type: \"retry_scheduled\", operation, attempt, maxAttempts, delayMs, errorMessage });\n\t\t\t},\n\t\t\tonRetryAttemptStart: async () => {\n\t\t\t\tawait emit({ type: \"retry_attempt_start\", operation, attempt: scheduledAttempt });\n\t\t\t},\n\t\t\tonRetryFinished: async (success, attempt, finalError) => {\n\t\t\t\tawait emit({ type: \"retry_finished\", operation, success, attempt, finalError });\n\t\t\t},\n\t\t},\n\t};\n}\n"]}