@northflare/runner 0.0.17 → 0.0.20

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 (154) hide show
  1. package/bin/northflare-runner +17 -3
  2. package/dist/components/claude-sdk-manager.d.ts +6 -3
  3. package/dist/components/claude-sdk-manager.d.ts.map +1 -1
  4. package/dist/components/claude-sdk-manager.js +62 -42
  5. package/dist/components/claude-sdk-manager.js.map +1 -1
  6. package/dist/components/codex-sdk-manager.d.ts +6 -3
  7. package/dist/components/codex-sdk-manager.d.ts.map +1 -1
  8. package/dist/components/codex-sdk-manager.js +60 -16
  9. package/dist/components/codex-sdk-manager.js.map +1 -1
  10. package/dist/components/enhanced-repository-manager.d.ts.map +1 -1
  11. package/dist/components/enhanced-repository-manager.js +2 -1
  12. package/dist/components/enhanced-repository-manager.js.map +1 -1
  13. package/dist/components/message-handler-sse.d.ts.map +1 -1
  14. package/dist/components/message-handler-sse.js +157 -116
  15. package/dist/components/message-handler-sse.js.map +1 -1
  16. package/dist/components/northflare-agent-sdk-manager.d.ts +10 -6
  17. package/dist/components/northflare-agent-sdk-manager.d.ts.map +1 -1
  18. package/dist/components/northflare-agent-sdk-manager.js +350 -98
  19. package/dist/components/northflare-agent-sdk-manager.js.map +1 -1
  20. package/dist/components/repository-manager.d.ts.map +1 -1
  21. package/dist/components/repository-manager.js +2 -1
  22. package/dist/components/repository-manager.js.map +1 -1
  23. package/dist/runner-sse.d.ts.map +1 -1
  24. package/dist/runner-sse.js +7 -0
  25. package/dist/runner-sse.js.map +1 -1
  26. package/dist/types/claude.d.ts +4 -1
  27. package/dist/types/claude.d.ts.map +1 -1
  28. package/dist/utils/console.d.ts +5 -8
  29. package/dist/utils/console.d.ts.map +1 -1
  30. package/dist/utils/console.js +28 -10
  31. package/dist/utils/console.js.map +1 -1
  32. package/dist/utils/debug.d.ts +10 -0
  33. package/dist/utils/debug.d.ts.map +1 -1
  34. package/dist/utils/debug.js +86 -8
  35. package/dist/utils/debug.js.map +1 -1
  36. package/dist/utils/logger.d.ts +2 -1
  37. package/dist/utils/logger.d.ts.map +1 -1
  38. package/dist/utils/logger.js +43 -13
  39. package/dist/utils/logger.js.map +1 -1
  40. package/dist/utils/message-log.d.ts +23 -0
  41. package/dist/utils/message-log.d.ts.map +1 -0
  42. package/dist/utils/message-log.js +69 -0
  43. package/dist/utils/message-log.js.map +1 -0
  44. package/dist/utils/status-line.d.ts +5 -1
  45. package/dist/utils/status-line.d.ts.map +1 -1
  46. package/dist/utils/status-line.js +13 -3
  47. package/dist/utils/status-line.js.map +1 -1
  48. package/package.json +3 -4
  49. package/{lib/codex-sdk/tsup.config.ts → tsup.config.ts} +2 -2
  50. package/lib/codex-sdk/.prettierignore +0 -3
  51. package/lib/codex-sdk/.prettierrc +0 -5
  52. package/lib/codex-sdk/README.md +0 -133
  53. package/lib/codex-sdk/dist/index.d.ts +0 -260
  54. package/lib/codex-sdk/dist/index.js +0 -426
  55. package/lib/codex-sdk/dist/samples/basic_streaming.d.ts +0 -3
  56. package/lib/codex-sdk/dist/samples/basic_streaming.d.ts.map +0 -1
  57. package/lib/codex-sdk/dist/samples/basic_streaming.js +0 -81
  58. package/lib/codex-sdk/dist/samples/basic_streaming.js.map +0 -1
  59. package/lib/codex-sdk/dist/samples/helpers.d.ts +0 -2
  60. package/lib/codex-sdk/dist/samples/helpers.d.ts.map +0 -1
  61. package/lib/codex-sdk/dist/samples/helpers.js +0 -6
  62. package/lib/codex-sdk/dist/samples/helpers.js.map +0 -1
  63. package/lib/codex-sdk/dist/samples/structured_output.d.ts +0 -3
  64. package/lib/codex-sdk/dist/samples/structured_output.d.ts.map +0 -1
  65. package/lib/codex-sdk/dist/samples/structured_output.js +0 -17
  66. package/lib/codex-sdk/dist/samples/structured_output.js.map +0 -1
  67. package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts +0 -3
  68. package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts.map +0 -1
  69. package/lib/codex-sdk/dist/samples/structured_output_zod.js +0 -16
  70. package/lib/codex-sdk/dist/samples/structured_output_zod.js.map +0 -1
  71. package/lib/codex-sdk/dist/src/codex.d.ts +0 -27
  72. package/lib/codex-sdk/dist/src/codex.d.ts.map +0 -1
  73. package/lib/codex-sdk/dist/src/codex.js +0 -33
  74. package/lib/codex-sdk/dist/src/codex.js.map +0 -1
  75. package/lib/codex-sdk/dist/src/codexOptions.d.ts +0 -11
  76. package/lib/codex-sdk/dist/src/codexOptions.d.ts.map +0 -1
  77. package/lib/codex-sdk/dist/src/codexOptions.js +0 -2
  78. package/lib/codex-sdk/dist/src/codexOptions.js.map +0 -1
  79. package/lib/codex-sdk/dist/src/events.d.ts +0 -60
  80. package/lib/codex-sdk/dist/src/events.d.ts.map +0 -1
  81. package/lib/codex-sdk/dist/src/events.js +0 -3
  82. package/lib/codex-sdk/dist/src/events.js.map +0 -1
  83. package/lib/codex-sdk/dist/src/exec.d.ts +0 -27
  84. package/lib/codex-sdk/dist/src/exec.d.ts.map +0 -1
  85. package/lib/codex-sdk/dist/src/exec.js +0 -264
  86. package/lib/codex-sdk/dist/src/exec.js.map +0 -1
  87. package/lib/codex-sdk/dist/src/index.d.ts +0 -9
  88. package/lib/codex-sdk/dist/src/index.d.ts.map +0 -1
  89. package/lib/codex-sdk/dist/src/index.js +0 -3
  90. package/lib/codex-sdk/dist/src/index.js.map +0 -1
  91. package/lib/codex-sdk/dist/src/items.d.ts +0 -103
  92. package/lib/codex-sdk/dist/src/items.d.ts.map +0 -1
  93. package/lib/codex-sdk/dist/src/items.js +0 -3
  94. package/lib/codex-sdk/dist/src/items.js.map +0 -1
  95. package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts +0 -6
  96. package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts.map +0 -1
  97. package/lib/codex-sdk/dist/src/outputSchemaFile.js +0 -33
  98. package/lib/codex-sdk/dist/src/outputSchemaFile.js.map +0 -1
  99. package/lib/codex-sdk/dist/src/thread.d.ts +0 -41
  100. package/lib/codex-sdk/dist/src/thread.d.ts.map +0 -1
  101. package/lib/codex-sdk/dist/src/thread.js +0 -109
  102. package/lib/codex-sdk/dist/src/thread.js.map +0 -1
  103. package/lib/codex-sdk/dist/src/threadOptions.d.ts +0 -16
  104. package/lib/codex-sdk/dist/src/threadOptions.d.ts.map +0 -1
  105. package/lib/codex-sdk/dist/src/threadOptions.js +0 -2
  106. package/lib/codex-sdk/dist/src/threadOptions.js.map +0 -1
  107. package/lib/codex-sdk/dist/src/turnOptions.d.ts +0 -7
  108. package/lib/codex-sdk/dist/src/turnOptions.d.ts.map +0 -1
  109. package/lib/codex-sdk/dist/src/turnOptions.js +0 -2
  110. package/lib/codex-sdk/dist/src/turnOptions.js.map +0 -1
  111. package/lib/codex-sdk/dist/tests/abort.test.d.ts +0 -2
  112. package/lib/codex-sdk/dist/tests/abort.test.d.ts.map +0 -1
  113. package/lib/codex-sdk/dist/tests/abort.test.js +0 -130
  114. package/lib/codex-sdk/dist/tests/abort.test.js.map +0 -1
  115. package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts +0 -6
  116. package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts.map +0 -1
  117. package/lib/codex-sdk/dist/tests/codexExecSpy.js +0 -28
  118. package/lib/codex-sdk/dist/tests/codexExecSpy.js.map +0 -1
  119. package/lib/codex-sdk/dist/tests/responsesProxy.d.ts +0 -56
  120. package/lib/codex-sdk/dist/tests/responsesProxy.d.ts.map +0 -1
  121. package/lib/codex-sdk/dist/tests/responsesProxy.js +0 -155
  122. package/lib/codex-sdk/dist/tests/responsesProxy.js.map +0 -1
  123. package/lib/codex-sdk/dist/tests/run.test.d.ts +0 -2
  124. package/lib/codex-sdk/dist/tests/run.test.d.ts.map +0 -1
  125. package/lib/codex-sdk/dist/tests/run.test.js +0 -524
  126. package/lib/codex-sdk/dist/tests/run.test.js.map +0 -1
  127. package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts +0 -2
  128. package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts.map +0 -1
  129. package/lib/codex-sdk/dist/tests/runStreamed.test.js +0 -153
  130. package/lib/codex-sdk/dist/tests/runStreamed.test.js.map +0 -1
  131. package/lib/codex-sdk/dist/tsup.config.d.ts +0 -3
  132. package/lib/codex-sdk/dist/tsup.config.js +0 -12
  133. package/lib/codex-sdk/eslint.config.js +0 -21
  134. package/lib/codex-sdk/jest.config.cjs +0 -31
  135. package/lib/codex-sdk/package.json +0 -65
  136. package/lib/codex-sdk/samples/basic_streaming.ts +0 -90
  137. package/lib/codex-sdk/samples/helpers.ts +0 -8
  138. package/lib/codex-sdk/samples/structured_output.ts +0 -22
  139. package/lib/codex-sdk/samples/structured_output_zod.ts +0 -19
  140. package/lib/codex-sdk/src/codex.ts +0 -38
  141. package/lib/codex-sdk/src/codexOptions.ts +0 -10
  142. package/lib/codex-sdk/src/events.ts +0 -80
  143. package/lib/codex-sdk/src/exec.ts +0 -336
  144. package/lib/codex-sdk/src/index.ts +0 -39
  145. package/lib/codex-sdk/src/items.ts +0 -127
  146. package/lib/codex-sdk/src/outputSchemaFile.ts +0 -40
  147. package/lib/codex-sdk/src/thread.ts +0 -155
  148. package/lib/codex-sdk/src/threadOptions.ts +0 -18
  149. package/lib/codex-sdk/src/turnOptions.ts +0 -6
  150. package/lib/codex-sdk/tests/abort.test.ts +0 -165
  151. package/lib/codex-sdk/tests/codexExecSpy.ts +0 -37
  152. package/lib/codex-sdk/tests/responsesProxy.ts +0 -225
  153. package/lib/codex-sdk/tests/run.test.ts +0 -687
  154. package/lib/codex-sdk/tests/runStreamed.test.ts +0 -211
@@ -1,18 +0,0 @@
1
- export type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
2
-
3
- export type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
4
-
5
- export type ModelReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh";
6
-
7
- export type ThreadOptions = {
8
- model?: string;
9
- sandboxMode?: SandboxMode;
10
- workingDirectory?: string;
11
- skipGitRepoCheck?: boolean;
12
- modelReasoningEffort?: ModelReasoningEffort;
13
- networkAccessEnabled?: boolean;
14
- webSearchEnabled?: boolean;
15
- approvalPolicy?: ApprovalMode;
16
- additionalDirectories?: string[];
17
- configOverrides?: Record<string, unknown>;
18
- };
@@ -1,6 +0,0 @@
1
- export type TurnOptions = {
2
- /** JSON schema describing the expected agent output. */
3
- outputSchema?: unknown;
4
- /** AbortSignal to cancel the turn. */
5
- signal?: AbortSignal;
6
- };
@@ -1,165 +0,0 @@
1
- import path from "node:path";
2
-
3
- import { describe, expect, it } from "@jest/globals";
4
-
5
- import { Codex } from "../src/codex";
6
-
7
- import {
8
- assistantMessage,
9
- responseCompleted,
10
- responseStarted,
11
- shell_call as shellCall,
12
- sse,
13
- SseResponseBody,
14
- startResponsesTestProxy,
15
- } from "./responsesProxy";
16
-
17
- const codexExecPath = path.join(process.cwd(), "..", "..", "codex-rs", "target", "debug", "codex");
18
-
19
- function* infiniteShellCall(): Generator<SseResponseBody> {
20
- while (true) {
21
- yield sse(responseStarted(), shellCall(), responseCompleted());
22
- }
23
- }
24
-
25
- describe("AbortSignal support", () => {
26
- it("aborts run() when signal is aborted", async () => {
27
- const { url, close } = await startResponsesTestProxy({
28
- statusCode: 200,
29
- responseBodies: infiniteShellCall(),
30
- });
31
-
32
- try {
33
- const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
34
- const thread = client.startThread();
35
-
36
- // Create an abort controller and abort it immediately
37
- const controller = new AbortController();
38
- controller.abort("Test abort");
39
-
40
- // The operation should fail because the signal is already aborted
41
- await expect(thread.run("Hello, world!", { signal: controller.signal })).rejects.toThrow();
42
- } finally {
43
- await close();
44
- }
45
- });
46
-
47
- it("aborts runStreamed() when signal is aborted", async () => {
48
- const { url, close } = await startResponsesTestProxy({
49
- statusCode: 200,
50
- responseBodies: infiniteShellCall(),
51
- });
52
-
53
- try {
54
- const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
55
- const thread = client.startThread();
56
-
57
- // Create an abort controller and abort it immediately
58
- const controller = new AbortController();
59
- controller.abort("Test abort");
60
-
61
- const { events } = await thread.runStreamed("Hello, world!", { signal: controller.signal });
62
-
63
- // Attempting to iterate should fail
64
- let iterationStarted = false;
65
- try {
66
- for await (const event of events) {
67
- iterationStarted = true;
68
- // Should not get here
69
- expect(event).toBeUndefined();
70
- }
71
- // If we get here, the test should fail
72
- throw new Error(
73
- "Expected iteration to throw due to aborted signal, but it completed successfully",
74
- );
75
- } catch (error) {
76
- // We expect an error to be thrown
77
- expect(iterationStarted).toBe(false); // Should fail before any iteration
78
- expect(error).toBeDefined();
79
- }
80
- } finally {
81
- await close();
82
- }
83
- });
84
-
85
- it("aborts run() when signal is aborted during execution", async () => {
86
- const { url, close } = await startResponsesTestProxy({
87
- statusCode: 200,
88
- responseBodies: infiniteShellCall(),
89
- });
90
-
91
- try {
92
- const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
93
- const thread = client.startThread();
94
-
95
- const controller = new AbortController();
96
-
97
- // Start the operation and abort it immediately after
98
- const runPromise = thread.run("Hello, world!", { signal: controller.signal });
99
-
100
- // Abort after a tiny delay to simulate aborting during execution
101
- setTimeout(() => controller.abort("Aborted during execution"), 10);
102
-
103
- // The operation should fail
104
- await expect(runPromise).rejects.toThrow();
105
- } finally {
106
- await close();
107
- }
108
- });
109
-
110
- it("aborts runStreamed() when signal is aborted during iteration", async () => {
111
- const { url, close } = await startResponsesTestProxy({
112
- statusCode: 200,
113
- responseBodies: infiniteShellCall(),
114
- });
115
-
116
- try {
117
- const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
118
- const thread = client.startThread();
119
-
120
- const controller = new AbortController();
121
-
122
- const { events } = await thread.runStreamed("Hello, world!", { signal: controller.signal });
123
-
124
- // Abort during iteration
125
- let eventCount = 0;
126
- await expect(
127
- (async () => {
128
- for await (const event of events) {
129
- void event; // Consume the event
130
- eventCount++;
131
- // Abort after first event
132
- if (eventCount === 5) {
133
- controller.abort("Aborted during iteration");
134
- }
135
- // Continue iterating - should eventually throw
136
- }
137
- })(),
138
- ).rejects.toThrow();
139
- } finally {
140
- await close();
141
- }
142
- });
143
-
144
- it("completes normally when signal is not aborted", async () => {
145
- const { url, close } = await startResponsesTestProxy({
146
- statusCode: 200,
147
- responseBodies: [sse(responseStarted(), assistantMessage("Hi!"), responseCompleted())],
148
- });
149
-
150
- try {
151
- const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
152
- const thread = client.startThread();
153
-
154
- const controller = new AbortController();
155
-
156
- // Don't abort - should complete successfully
157
- const result = await thread.run("Hello, world!", { signal: controller.signal });
158
-
159
- expect(result.finalResponse).toBe("Hi!");
160
- expect(result.items).toHaveLength(1);
161
- } finally {
162
- await close();
163
- }
164
- });
165
- });
@@ -1,37 +0,0 @@
1
- import * as child_process from "node:child_process";
2
-
3
- jest.mock("node:child_process", () => {
4
- const actual = jest.requireActual<typeof import("node:child_process")>("node:child_process");
5
- return { ...actual, spawn: jest.fn(actual.spawn) };
6
- });
7
-
8
- const actualChildProcess =
9
- jest.requireActual<typeof import("node:child_process")>("node:child_process");
10
- const spawnMock = child_process.spawn as jest.MockedFunction<typeof actualChildProcess.spawn>;
11
-
12
- export function codexExecSpy(): {
13
- args: string[][];
14
- envs: (Record<string, string> | undefined)[];
15
- restore: () => void;
16
- } {
17
- const previousImplementation = spawnMock.getMockImplementation() ?? actualChildProcess.spawn;
18
- const args: string[][] = [];
19
- const envs: (Record<string, string> | undefined)[] = [];
20
-
21
- spawnMock.mockImplementation(((...spawnArgs: Parameters<typeof child_process.spawn>) => {
22
- const commandArgs = spawnArgs[1];
23
- args.push(Array.isArray(commandArgs) ? [...commandArgs] : []);
24
- const options = spawnArgs[2] as child_process.SpawnOptions | undefined;
25
- envs.push(options?.env as Record<string, string> | undefined);
26
- return previousImplementation(...spawnArgs);
27
- }) as typeof actualChildProcess.spawn);
28
-
29
- return {
30
- args,
31
- envs,
32
- restore: () => {
33
- spawnMock.mockClear();
34
- spawnMock.mockImplementation(previousImplementation);
35
- },
36
- };
37
- }
@@ -1,225 +0,0 @@
1
- import http from "node:http";
2
-
3
- const DEFAULT_RESPONSE_ID = "resp_mock";
4
- const DEFAULT_MESSAGE_ID = "msg_mock";
5
-
6
- type ResponseCompletedUsage = {
7
- input_tokens: number;
8
- input_tokens_details: { cached_tokens: number } | null;
9
- output_tokens: number;
10
- output_tokens_details: { reasoning_tokens: number } | null;
11
- total_tokens: number;
12
- };
13
-
14
- const DEFAULT_COMPLETED_USAGE: ResponseCompletedUsage = {
15
- input_tokens: 42,
16
- input_tokens_details: { cached_tokens: 12 },
17
- output_tokens: 5,
18
- output_tokens_details: null,
19
- total_tokens: 47,
20
- };
21
-
22
- export type SseEvent = {
23
- type: string;
24
- [key: string]: unknown;
25
- };
26
-
27
- export type SseResponseBody = {
28
- kind: "sse";
29
- events: SseEvent[];
30
- };
31
-
32
- export type ResponsesProxyOptions = {
33
- responseBodies: Generator<SseResponseBody> | SseResponseBody[];
34
- statusCode?: number;
35
- };
36
-
37
- export type ResponsesProxy = {
38
- url: string;
39
- close: () => Promise<void>;
40
- requests: RecordedRequest[];
41
- };
42
-
43
- export type ResponsesApiRequest = {
44
- model?: string;
45
- input: Array<{
46
- role: string;
47
- content?: Array<{ type: string; text: string }>;
48
- }>;
49
- text?: {
50
- format?: Record<string, unknown>;
51
- };
52
- };
53
-
54
- export type RecordedRequest = {
55
- body: string;
56
- json: ResponsesApiRequest;
57
- headers: http.IncomingHttpHeaders;
58
- };
59
-
60
- function formatSseEvent(event: SseEvent): string {
61
- return `event: ${event.type}\n` + `data: ${JSON.stringify(event)}\n\n`;
62
- }
63
-
64
- export async function startResponsesTestProxy(
65
- options: ResponsesProxyOptions,
66
- ): Promise<ResponsesProxy> {
67
- function* createGenerator(array: SseResponseBody[]): Generator<SseResponseBody> {
68
- for (const elem of array) {
69
- yield elem;
70
- }
71
- throw new Error("not enough responses provided");
72
- }
73
-
74
- const responseBodies: Generator<SseResponseBody> = Array.isArray(options.responseBodies)
75
- ? createGenerator(options.responseBodies)
76
- : options.responseBodies;
77
-
78
- const requests: RecordedRequest[] = [];
79
-
80
- function readRequestBody(req: http.IncomingMessage): Promise<string> {
81
- return new Promise<string>((resolve, reject) => {
82
- const chunks: Buffer[] = [];
83
- req.on("data", (chunk) => {
84
- chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
85
- });
86
- req.on("end", () => {
87
- resolve(Buffer.concat(chunks).toString("utf8"));
88
- });
89
- req.on("error", reject);
90
- });
91
- }
92
-
93
- const server = http.createServer((req, res) => {
94
- async function handle(): Promise<void> {
95
- if (req.method === "POST" && req.url === "/responses") {
96
- const body = await readRequestBody(req);
97
- const json = JSON.parse(body);
98
- requests.push({ body, json, headers: { ...req.headers } });
99
-
100
- const status = options.statusCode ?? 200;
101
- res.statusCode = status;
102
- res.setHeader("content-type", "text/event-stream");
103
-
104
- const responseBody = responseBodies.next().value;
105
- for (const event of responseBody.events) {
106
- res.write(formatSseEvent(event));
107
- }
108
- res.end();
109
- return;
110
- }
111
-
112
- res.statusCode = 404;
113
- res.end();
114
- }
115
-
116
- handle().catch(() => {
117
- res.statusCode = 500;
118
- res.end();
119
- });
120
- });
121
-
122
- const url = await new Promise<string>((resolve, reject) => {
123
- server.listen(0, "127.0.0.1", () => {
124
- const address = server.address();
125
- if (!address || typeof address === "string") {
126
- reject(new Error("Unable to determine proxy address"));
127
- return;
128
- }
129
- server.off("error", reject);
130
- const info = address;
131
- resolve(`http://${info.address}:${info.port}`);
132
- });
133
- server.once("error", reject);
134
- });
135
-
136
- async function close(): Promise<void> {
137
- await new Promise<void>((resolve, reject) => {
138
- server.close((err) => {
139
- if (err) {
140
- reject(err);
141
- return;
142
- }
143
- resolve();
144
- });
145
- });
146
- }
147
- return { url, close, requests };
148
- }
149
-
150
- export function sse(...events: SseEvent[]): SseResponseBody {
151
- return {
152
- kind: "sse",
153
- events,
154
- };
155
- }
156
-
157
- export function responseStarted(responseId: string = DEFAULT_RESPONSE_ID): SseEvent {
158
- return {
159
- type: "response.created",
160
- response: {
161
- id: responseId,
162
- },
163
- };
164
- }
165
-
166
- export function assistantMessage(text: string, itemId: string = DEFAULT_MESSAGE_ID): SseEvent {
167
- return {
168
- type: "response.output_item.done",
169
- item: {
170
- type: "message",
171
- role: "assistant",
172
- id: itemId,
173
- content: [
174
- {
175
- type: "output_text",
176
- text,
177
- },
178
- ],
179
- },
180
- };
181
- }
182
-
183
- export function shell_call(): SseEvent {
184
- const command = ["bash", "-lc", "echo 'Hello, world!'"];
185
- return {
186
- type: "response.output_item.done",
187
- item: {
188
- type: "function_call",
189
- call_id: `call_id${Math.random().toString(36).slice(2)}`,
190
- name: "shell",
191
- arguments: JSON.stringify({
192
- command,
193
- timeout_ms: 100,
194
- }),
195
- },
196
- };
197
- }
198
-
199
- export function responseFailed(errorMessage: string): SseEvent {
200
- return {
201
- type: "error",
202
- error: { code: "rate_limit_exceeded", message: errorMessage },
203
- };
204
- }
205
-
206
- export function responseCompleted(
207
- responseId: string = DEFAULT_RESPONSE_ID,
208
- usage: ResponseCompletedUsage = DEFAULT_COMPLETED_USAGE,
209
- ): SseEvent {
210
- const inputDetails = usage.input_tokens_details ? { ...usage.input_tokens_details } : null;
211
- const outputDetails = usage.output_tokens_details ? { ...usage.output_tokens_details } : null;
212
- return {
213
- type: "response.completed",
214
- response: {
215
- id: responseId,
216
- usage: {
217
- input_tokens: usage.input_tokens,
218
- input_tokens_details: inputDetails,
219
- output_tokens: usage.output_tokens,
220
- output_tokens_details: outputDetails,
221
- total_tokens: usage.total_tokens,
222
- },
223
- },
224
- };
225
- }