@cydm/pie 1.0.13 → 1.0.15

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.
@@ -3,7 +3,8 @@ import {
3
3
  Agent,
4
4
  agentLoop,
5
5
  agentLoopContinue
6
- } from "./chunk-D7NAXU7F.js";
6
+ } from "./chunk-VE2HDCNB.js";
7
+ import "./chunk-5DA2D3K2.js";
7
8
  import "./chunk-TG2EQLX2.js";
8
9
  export {
9
10
  Agent,
@@ -0,0 +1,94 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ EventStream
4
+ } from "./chunk-5DA2D3K2.js";
5
+ import "./chunk-TG2EQLX2.js";
6
+
7
+ // src/app/test-stream.ts
8
+ function createAssistantMessage(model, text, stopReason = "stop", errorMessage) {
9
+ return {
10
+ role: "assistant",
11
+ content: [{ type: "text", text }],
12
+ api: model.api,
13
+ provider: model.provider,
14
+ model: model.id,
15
+ usage: {
16
+ input: 1,
17
+ output: text ? 1 : 0,
18
+ cacheRead: 0,
19
+ cacheWrite: 0,
20
+ totalTokens: text ? 2 : 1,
21
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
22
+ },
23
+ stopReason,
24
+ errorMessage,
25
+ timestamp: Date.now()
26
+ };
27
+ }
28
+ function parseMockStreamSequence(value) {
29
+ const parsed = JSON.parse(value);
30
+ if (!Array.isArray(parsed)) {
31
+ throw new Error("PIE_TEST_MOCK_STREAM_SEQUENCE must be a JSON array");
32
+ }
33
+ return parsed.map((item) => {
34
+ if (!item || typeof item !== "object") {
35
+ throw new Error("PIE_TEST_MOCK_STREAM_SEQUENCE entries must be objects");
36
+ }
37
+ const record = item;
38
+ if (record.type === "error" && typeof record.error === "string") {
39
+ return {
40
+ type: "error",
41
+ error: record.error,
42
+ partialText: typeof record.partialText === "string" ? record.partialText : void 0
43
+ };
44
+ }
45
+ if (record.type === "text" && typeof record.text === "string") {
46
+ return { type: "text", text: record.text };
47
+ }
48
+ throw new Error("PIE_TEST_MOCK_STREAM_SEQUENCE entries must be text or error steps");
49
+ });
50
+ }
51
+ function createTestStreamFnFromSequenceEnv(value = process.env.PIE_TEST_MOCK_STREAM_SEQUENCE) {
52
+ if (!value) {
53
+ return void 0;
54
+ }
55
+ const steps = parseMockStreamSequence(value);
56
+ let callIndex = 0;
57
+ return async (model) => {
58
+ const step = steps[Math.min(callIndex, steps.length - 1)];
59
+ callIndex += 1;
60
+ const stream = new EventStream(
61
+ (event) => event.type === "done" || event.type === "error",
62
+ (event) => event.type === "done" ? event.message : event.error
63
+ );
64
+ queueMicrotask(() => {
65
+ if (!step) {
66
+ const message2 = createAssistantMessage(model, "");
67
+ stream.push({ type: "done", reason: "stop", message: message2 });
68
+ return;
69
+ }
70
+ if (step.type === "error") {
71
+ if (step.partialText) {
72
+ const partial = createAssistantMessage(model, step.partialText);
73
+ stream.push({ type: "start", partial });
74
+ stream.push({ type: "text_start", contentIndex: 0, partial });
75
+ stream.push({ type: "text_delta", contentIndex: 0, delta: step.partialText, partial });
76
+ stream.push({ type: "text_end", contentIndex: 0, content: step.partialText, partial });
77
+ }
78
+ const error = createAssistantMessage(model, "", "error", step.error);
79
+ stream.push({ type: "error", reason: "error", error });
80
+ return;
81
+ }
82
+ const message = createAssistantMessage(model, step.text);
83
+ stream.push({ type: "start", partial: message });
84
+ stream.push({ type: "text_start", contentIndex: 0, partial: message });
85
+ stream.push({ type: "text_delta", contentIndex: 0, delta: step.text, partial: message });
86
+ stream.push({ type: "text_end", contentIndex: 0, content: step.text, partial: message });
87
+ stream.push({ type: "done", reason: "stop", message });
88
+ });
89
+ return stream;
90
+ };
91
+ }
92
+ export {
93
+ createTestStreamFnFromSequenceEnv
94
+ };