@nyte-ai/plugin 0.0.0-stage → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/THIRD-PARTY-NOTICES.md +866 -0
- package/dist/chunks/billing-0y7dfkp2.js +146 -0
- package/dist/chunks/billing-2v3g7rd9.js +190 -0
- package/dist/chunks/billing-3j77ss7y.js +86 -0
- package/dist/chunks/billing-3scqmkzb.js +559 -0
- package/dist/chunks/billing-4vz9pxyx.js +22 -0
- package/dist/chunks/billing-6z2kgtyt.js +51 -0
- package/dist/chunks/billing-8rjk35gr.js +444 -0
- package/dist/chunks/billing-9nn3yp18.js +176 -0
- package/dist/chunks/billing-9qc0eqh4.js +174 -0
- package/dist/chunks/billing-a9vqn66p.js +351 -0
- package/dist/chunks/billing-bv5zr32b.js +369 -0
- package/dist/chunks/billing-cy1rg619.js +302 -0
- package/dist/chunks/billing-ejx2hv52.js +323 -0
- package/dist/chunks/billing-h13r0byk.js +80 -0
- package/dist/chunks/billing-hg64tqf1.js +97 -0
- package/dist/chunks/billing-j643d12p.js +197 -0
- package/dist/chunks/billing-kn3d30b4.js +276 -0
- package/dist/chunks/billing-mvc33pv6.js +36 -0
- package/dist/chunks/billing-s4rrspsk.js +7 -0
- package/dist/chunks/billing-svrhh5a5.js +307 -0
- package/dist/chunks/billing-sxc70w72.js +161 -0
- package/dist/chunks/billing-t1qrxe16.js +41 -0
- package/dist/chunks/billing-tm34gm2p.js +528 -0
- package/dist/chunks/billing-tzr3cebf.js +20 -0
- package/dist/chunks/billing-v3hg5rc7.js +373 -0
- package/dist/chunks/billing-wmcbg6fw.js +52 -0
- package/dist/chunks/billing-ye3wk5r3.js +205 -0
- package/dist/chunks/billing-zfpm2rt0.js +29 -0
- package/dist/examples/claude-code/LICENSE +21 -0
- package/dist/examples/claude-code/billing.d.ts +7 -0
- package/dist/examples/claude-code/billing.js +11 -0
- package/dist/examples/claude-code/claude-cli.d.ts +35 -0
- package/dist/examples/claude-code/claude-cli.js +15 -0
- package/dist/examples/claude-code/env.d.ts +1 -0
- package/dist/examples/claude-code/env.js +6 -0
- package/dist/examples/claude-code/index.d.ts +24 -0
- package/dist/examples/claude-code/index.js +149 -0
- package/dist/examples/claude-code/inert-mcp.d.ts +1 -0
- package/dist/examples/claude-code/inert-mcp.js +6 -0
- package/dist/examples/claude-code/model-catalog.d.ts +27 -0
- package/dist/examples/claude-code/model-catalog.js +12 -0
- package/dist/examples/claude-code/process.d.ts +22 -0
- package/dist/examples/claude-code/process.js +25 -0
- package/dist/examples/claude-code/replay.d.ts +4 -0
- package/dist/examples/claude-code/replay.js +11 -0
- package/dist/examples/claude-code/stream.d.ts +3 -0
- package/dist/examples/claude-code/stream.js +16 -0
- package/dist/examples/claude-code/transcript.d.ts +83 -0
- package/dist/examples/claude-code/transcript.js +23 -0
- package/dist/examples/claude-code/turn-relay.d.ts +48 -0
- package/dist/examples/claude-code/turn-relay.js +9 -0
- package/dist/examples/claude-code/wire.d.ts +372 -0
- package/dist/examples/claude-code/wire.js +18 -0
- package/dist/src/acp/connection.d.ts +24 -0
- package/dist/src/acp/connection.js +8 -0
- package/dist/src/acp/index.d.ts +54 -0
- package/dist/src/acp/index.js +1005 -0
- package/dist/src/acp/registry.d.ts +18 -0
- package/dist/src/acp/registry.js +9 -0
- package/dist/src/acp/thread.d.ts +46 -0
- package/dist/src/acp/thread.js +7 -0
- package/dist/src/acp/transcript.d.ts +8 -0
- package/dist/src/acp/transcript.js +11 -0
- package/dist/src/acp/translate.d.ts +33 -0
- package/dist/src/acp/translate.js +20 -0
- package/dist/src/approvals/approvals.d.ts +189 -0
- package/dist/src/approvals/approvals.js +143 -0
- package/dist/src/approvals/schema.d.ts +169 -0
- package/dist/src/approvals/schema.js +18 -0
- package/dist/src/bash-description.d.ts +30 -0
- package/dist/src/bash-description.js +18 -0
- package/dist/src/browser-tools.d.ts +25 -0
- package/dist/src/browser-tools.js +246 -0
- package/dist/src/canvas/canvas-compile.d.ts +48 -0
- package/dist/src/canvas/canvas-compile.js +8 -0
- package/dist/src/canvas/canvas-libraries.d.ts +32 -0
- package/dist/src/canvas/canvas-libraries.js +6 -0
- package/dist/src/canvas/canvas-preview.d.ts +107 -0
- package/dist/src/canvas/canvas-preview.js +12 -0
- package/dist/src/canvas/canvas-protocol.d.ts +184 -0
- package/dist/src/canvas/canvas-protocol.js +75 -0
- package/dist/src/canvas/canvas.d.ts +50 -0
- package/dist/src/canvas/canvas.js +221 -0
- package/dist/src/canvas/schema.d.ts +47 -0
- package/dist/src/canvas/schema.js +8 -0
- package/dist/src/claude-code-sdk/index.d.ts +35 -0
- package/dist/src/claude-code-sdk/index.js +379 -0
- package/dist/src/claude-code-sdk/session.d.ts +50 -0
- package/dist/src/claude-code-sdk/session.js +7 -0
- package/dist/src/claude-code-sdk/transcript.d.ts +19 -0
- package/dist/src/claude-code-sdk/transcript.js +15 -0
- package/dist/src/claude-code-sdk/translate.d.ts +18 -0
- package/dist/src/claude-code-sdk/translate.js +20 -0
- package/dist/src/client/mount.d.ts +44 -0
- package/dist/src/client/mount.js +252 -0
- package/dist/src/client/notifications.d.ts +36 -0
- package/dist/src/client/notifications.js +24 -0
- package/dist/src/client/presentation.d.ts +362 -0
- package/dist/src/client/presentation.js +391 -0
- package/dist/src/client/transcript-tui.d.ts +23 -0
- package/dist/src/client/transcript-tui.js +20 -0
- package/dist/src/client/transcript.d.ts +23 -0
- package/dist/src/client/transcript.js +51 -0
- package/dist/src/client.d.ts +53 -0
- package/dist/src/client.js +22 -0
- package/dist/src/codemode-runtime.d.ts +11 -0
- package/dist/src/codemode-runtime.js +10 -0
- package/dist/src/codemode-worker.d.ts +1 -0
- package/dist/src/codemode-worker.js +2 -0
- package/dist/src/codemode.d.ts +21 -0
- package/dist/src/codemode.js +170 -0
- package/dist/src/core.d.ts +43 -0
- package/dist/src/core.js +11 -0
- package/dist/src/find-on-path.d.ts +4 -0
- package/dist/src/find-on-path.js +8 -0
- package/dist/src/openai-astra-context.d.ts +23 -0
- package/dist/src/openai-astra-context.js +14 -0
- package/dist/src/openai-compaction.d.ts +15 -0
- package/dist/src/openai-compaction.js +55 -0
- package/dist/src/question/client/questions-tui.d.ts +9 -0
- package/dist/src/question/client/questions-tui.js +19 -0
- package/dist/src/question/client/questions.d.ts +9 -0
- package/dist/src/question/client/questions.js +160 -0
- package/dist/src/question/question.d.ts +63 -0
- package/dist/src/question/question.js +9 -0
- package/dist/src/question/schema.d.ts +101 -0
- package/dist/src/question/schema.js +14 -0
- package/dist/src/rename.d.ts +79 -0
- package/dist/src/rename.js +91 -0
- package/dist/src/telemetry.d.ts +36 -0
- package/dist/src/telemetry.js +84 -0
- package/dist/src/web-search.d.ts +78 -0
- package/dist/src/web-search.js +219 -0
- package/package.json +190 -3
- package/README.md +0 -3
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// examples/claude-code/wire.ts
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { Value } from "typebox/value";
|
|
4
|
+
var recordSchema = Type.Record(Type.String(), Type.Unknown());
|
|
5
|
+
var usageSchema = Type.Object({
|
|
6
|
+
input_tokens: Type.Number(),
|
|
7
|
+
output_tokens: Type.Number(),
|
|
8
|
+
cache_read_input_tokens: Type.Optional(Type.Number()),
|
|
9
|
+
cache_creation_input_tokens: Type.Optional(Type.Number()),
|
|
10
|
+
cache_creation: Type.Optional(Type.Object({ ephemeral_1h_input_tokens: Type.Optional(Type.Number()) })),
|
|
11
|
+
output_tokens_details: Type.Optional(Type.Object({ thinking_tokens: Type.Optional(Type.Number()) }))
|
|
12
|
+
});
|
|
13
|
+
var contentSchema = Type.Union([
|
|
14
|
+
Type.Object({ type: Type.Literal("text"), text: Type.String() }),
|
|
15
|
+
Type.Object({
|
|
16
|
+
type: Type.Literal("thinking"),
|
|
17
|
+
thinking: Type.String(),
|
|
18
|
+
signature: Type.Optional(Type.String())
|
|
19
|
+
}),
|
|
20
|
+
Type.Object({ type: Type.Literal("redacted_thinking"), data: Type.String() }),
|
|
21
|
+
Type.Object({
|
|
22
|
+
type: Type.Literal("tool_use"),
|
|
23
|
+
id: Type.String(),
|
|
24
|
+
name: Type.String(),
|
|
25
|
+
input: recordSchema
|
|
26
|
+
})
|
|
27
|
+
]);
|
|
28
|
+
var messageSchema2 = Type.Intersect([
|
|
29
|
+
recordSchema,
|
|
30
|
+
Type.Object({
|
|
31
|
+
id: Type.Optional(Type.String()),
|
|
32
|
+
role: Type.Literal("assistant"),
|
|
33
|
+
content: Type.Array(contentSchema),
|
|
34
|
+
usage: Type.Optional(usageSchema),
|
|
35
|
+
stop_reason: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
36
|
+
stop_sequence: Type.Optional(Type.Union([Type.String(), Type.Null()]))
|
|
37
|
+
})
|
|
38
|
+
]);
|
|
39
|
+
var streamEventSchema = Type.Union([
|
|
40
|
+
Type.Object({ type: Type.Literal("message_start"), message: messageSchema2 }),
|
|
41
|
+
Type.Object({
|
|
42
|
+
type: Type.Literal("content_block_start"),
|
|
43
|
+
index: Type.Integer({ minimum: 0 }),
|
|
44
|
+
content_block: contentSchema
|
|
45
|
+
}),
|
|
46
|
+
Type.Object({
|
|
47
|
+
type: Type.Literal("content_block_delta"),
|
|
48
|
+
index: Type.Integer({ minimum: 0 }),
|
|
49
|
+
delta: Type.Union([
|
|
50
|
+
Type.Object({ type: Type.Literal("text_delta"), text: Type.String() }),
|
|
51
|
+
Type.Object({ type: Type.Literal("thinking_delta"), thinking: Type.String() }),
|
|
52
|
+
Type.Object({ type: Type.Literal("signature_delta"), signature: Type.String() }),
|
|
53
|
+
Type.Object({ type: Type.Literal("input_json_delta"), partial_json: Type.String() })
|
|
54
|
+
])
|
|
55
|
+
}),
|
|
56
|
+
Type.Object({ type: Type.Literal("content_block_stop"), index: Type.Integer({ minimum: 0 }) }),
|
|
57
|
+
Type.Object({
|
|
58
|
+
type: Type.Literal("message_delta"),
|
|
59
|
+
delta: Type.Object({
|
|
60
|
+
stop_reason: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
61
|
+
stop_sequence: Type.Optional(Type.Union([Type.String(), Type.Null()]))
|
|
62
|
+
}),
|
|
63
|
+
usage: Type.Optional(Type.Partial(usageSchema))
|
|
64
|
+
}),
|
|
65
|
+
Type.Object({ type: Type.Literal("message_stop") }),
|
|
66
|
+
Type.Object({
|
|
67
|
+
type: Type.Literal("error"),
|
|
68
|
+
error: Type.Optional(Type.Object({ type: Type.Optional(Type.String()), message: Type.Optional(Type.String()) }))
|
|
69
|
+
})
|
|
70
|
+
]);
|
|
71
|
+
var outputEventSchema = Type.Union([
|
|
72
|
+
Type.Object({
|
|
73
|
+
type: Type.Literal("assistant"),
|
|
74
|
+
message: messageSchema2,
|
|
75
|
+
error: Type.Optional(Type.Unknown())
|
|
76
|
+
}),
|
|
77
|
+
Type.Object({
|
|
78
|
+
type: Type.Literal("result"),
|
|
79
|
+
subtype: Type.Optional(Type.String()),
|
|
80
|
+
is_error: Type.Optional(Type.Boolean()),
|
|
81
|
+
num_turns: Type.Optional(Type.Number()),
|
|
82
|
+
usage: Type.Optional(usageSchema),
|
|
83
|
+
total_cost_usd: Type.Optional(Type.Number()),
|
|
84
|
+
modelUsage: Type.Optional(recordSchema)
|
|
85
|
+
}),
|
|
86
|
+
Type.Object({ type: Type.Literal("stream_event"), event: streamEventSchema }),
|
|
87
|
+
Type.Object({
|
|
88
|
+
type: Type.Literal("rate_limit_event"),
|
|
89
|
+
rate_limit_info: Type.Optional(Type.Object({
|
|
90
|
+
status: Type.Optional(Type.String()),
|
|
91
|
+
rateLimitType: Type.Optional(Type.String()),
|
|
92
|
+
resetsAt: Type.Optional(Type.Number()),
|
|
93
|
+
isUsingOverage: Type.Optional(Type.Boolean()),
|
|
94
|
+
overageStatus: Type.Optional(Type.String()),
|
|
95
|
+
overageDisabledReason: Type.Optional(Type.String())
|
|
96
|
+
}))
|
|
97
|
+
}),
|
|
98
|
+
Type.Object({ type: Type.Literal("control_response"), response: recordSchema })
|
|
99
|
+
]);
|
|
100
|
+
var requestMessageSchema = Type.Object({
|
|
101
|
+
role: Type.Optional(Type.String()),
|
|
102
|
+
content: Type.Optional(Type.Unknown())
|
|
103
|
+
});
|
|
104
|
+
var requestMessagesSchema = Type.Array(requestMessageSchema);
|
|
105
|
+
var requestSchema = Type.Intersect([
|
|
106
|
+
recordSchema,
|
|
107
|
+
Type.Object({ messages: requestMessagesSchema, system: Type.Optional(Type.Unknown()) })
|
|
108
|
+
]);
|
|
109
|
+
function matchesRecord2(value) {
|
|
110
|
+
return Value.Check(recordSchema, value);
|
|
111
|
+
}
|
|
112
|
+
function parseRecord2(text) {
|
|
113
|
+
const value = JSON.parse(text);
|
|
114
|
+
if (!matchesRecord2(value))
|
|
115
|
+
throw new Error("Expected a JSON object");
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
function parseStreamEvent2(text) {
|
|
119
|
+
const value = JSON.parse(text);
|
|
120
|
+
if (matchesRecord2(value) && value.type === "ping")
|
|
121
|
+
return;
|
|
122
|
+
if (!Value.Check(streamEventSchema, value))
|
|
123
|
+
throw new Error("Invalid Anthropic stream event");
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
function parseOutputEvent2(text) {
|
|
127
|
+
const value = parseRecord2(text);
|
|
128
|
+
if (!["assistant", "result", "stream_event", "rate_limit_event", "control_response"].includes(String(value.type)))
|
|
129
|
+
return;
|
|
130
|
+
if (!Value.Check(outputEventSchema, value))
|
|
131
|
+
throw new Error("Invalid Claude Code output event");
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
function parseRequest2(body) {
|
|
135
|
+
const value = JSON.parse(body.toString("utf8"));
|
|
136
|
+
if (!Value.Check(requestSchema, value))
|
|
137
|
+
throw new Error("Invalid Claude Code request");
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
function parseRequestMessages2(value) {
|
|
141
|
+
if (!Value.Check(requestMessagesSchema, value))
|
|
142
|
+
throw new Error("Invalid Claude Code replay messages");
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { messageSchema2, matchesRecord2, parseRecord2, parseStreamEvent2, parseOutputEvent2, parseRequest2, parseRequestMessages2 };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLAUDE_CODE_PROVIDER2,
|
|
3
|
+
MIRROR_TOOL3,
|
|
4
|
+
BACKGROUND_TOOL2,
|
|
5
|
+
NYTE_TOOL_PREFIX2
|
|
6
|
+
} from "./billing-ye3wk5r3.js";
|
|
7
|
+
|
|
8
|
+
// src/claude-code-sdk/transcript.ts
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { Type } from "typebox";
|
|
11
|
+
import { Value } from "typebox/value";
|
|
12
|
+
var IMAGE_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
13
|
+
var mirrorArguments3 = Type.Object({
|
|
14
|
+
id: Type.String(),
|
|
15
|
+
name: Type.String(),
|
|
16
|
+
input: Type.Record(Type.String(), Type.Unknown())
|
|
17
|
+
});
|
|
18
|
+
function readMirrorCall(call) {
|
|
19
|
+
if (call.name !== MIRROR_TOOL3 || !Value.Check(mirrorArguments3, call.arguments))
|
|
20
|
+
return;
|
|
21
|
+
return call.arguments;
|
|
22
|
+
}
|
|
23
|
+
function mediaBlock(content) {
|
|
24
|
+
if (content.type === "text")
|
|
25
|
+
return { type: "text", text: content.text };
|
|
26
|
+
const mediaType = IMAGE_TYPES.find((type) => type === content.mimeType);
|
|
27
|
+
return mediaType === undefined ? { type: "text", text: `(${content.mimeType} image omitted)` } : { type: "image", source: { type: "base64", media_type: mediaType, data: content.data } };
|
|
28
|
+
}
|
|
29
|
+
function userBlocks3(message) {
|
|
30
|
+
return typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content.map(mediaBlock);
|
|
31
|
+
}
|
|
32
|
+
function text(content) {
|
|
33
|
+
return typeof content === "string" ? content : content.map((block) => block.type === "text" ? block.text : `[${block.mimeType}]`).join("");
|
|
34
|
+
}
|
|
35
|
+
function messageKey3(message) {
|
|
36
|
+
if (message.role === "user")
|
|
37
|
+
return `u:${text(message.content)}`;
|
|
38
|
+
if (message.role === "toolResult")
|
|
39
|
+
return `t:${message.toolCallId}`;
|
|
40
|
+
if (message.role === "system")
|
|
41
|
+
return "s";
|
|
42
|
+
return `a:${message.content.flatMap((block) => block.type === "toolCall" ? [block.id] : []).join(",")}`;
|
|
43
|
+
}
|
|
44
|
+
function toParams(messages, model) {
|
|
45
|
+
const params = [];
|
|
46
|
+
const claude = new Map;
|
|
47
|
+
const foreign = new Map;
|
|
48
|
+
const skipped = new Set;
|
|
49
|
+
const push = (role, content) => {
|
|
50
|
+
if (content.length === 0)
|
|
51
|
+
return;
|
|
52
|
+
const last = params.at(-1);
|
|
53
|
+
if (last?.role === role && Array.isArray(last.content))
|
|
54
|
+
last.content.push(...content);
|
|
55
|
+
else
|
|
56
|
+
params.push({ role, content: [...content] });
|
|
57
|
+
};
|
|
58
|
+
const closeCalls = () => {
|
|
59
|
+
push("user", [...claude.values()].map((id) => ({
|
|
60
|
+
type: "tool_result",
|
|
61
|
+
tool_use_id: id,
|
|
62
|
+
content: "No result provided",
|
|
63
|
+
is_error: true
|
|
64
|
+
})));
|
|
65
|
+
claude.clear();
|
|
66
|
+
};
|
|
67
|
+
for (const message of messages) {
|
|
68
|
+
if (message.role === "system")
|
|
69
|
+
continue;
|
|
70
|
+
if (message.role === "toolResult") {
|
|
71
|
+
const id = claude.get(message.toolCallId);
|
|
72
|
+
const name = foreign.get(message.toolCallId);
|
|
73
|
+
if (skipped.has(message.toolCallId))
|
|
74
|
+
continue;
|
|
75
|
+
if (id !== undefined) {
|
|
76
|
+
claude.delete(message.toolCallId);
|
|
77
|
+
push("user", [
|
|
78
|
+
{
|
|
79
|
+
type: "tool_result",
|
|
80
|
+
tool_use_id: id,
|
|
81
|
+
content: message.content.map(mediaBlock),
|
|
82
|
+
is_error: message.isError
|
|
83
|
+
}
|
|
84
|
+
]);
|
|
85
|
+
} else {
|
|
86
|
+
push("user", [
|
|
87
|
+
{ type: "text", text: `[${name ?? message.toolName} result]
|
|
88
|
+
${text(message.content)}` }
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
closeCalls();
|
|
94
|
+
if (message.role === "user") {
|
|
95
|
+
push("user", userBlocks3(message));
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (message.stopReason === "error" || message.stopReason === "aborted")
|
|
99
|
+
continue;
|
|
100
|
+
const signed = message.provider === CLAUDE_CODE_PROVIDER2 && message.model === model;
|
|
101
|
+
push("assistant", message.content.flatMap((block) => {
|
|
102
|
+
if (block.type === "text")
|
|
103
|
+
return block.text.trim() === "" ? [] : [{ type: "text", text: block.text }];
|
|
104
|
+
if (block.type === "thinking") {
|
|
105
|
+
if (!signed || block.thinkingSignature === undefined || block.thinkingSignature === "")
|
|
106
|
+
return [];
|
|
107
|
+
return block.redacted === true ? [{ type: "redacted_thinking", data: block.thinkingSignature }] : [{ type: "thinking", thinking: block.thinking, signature: block.thinkingSignature }];
|
|
108
|
+
}
|
|
109
|
+
const call = readMirrorCall(block);
|
|
110
|
+
if (call?.name === BACKGROUND_TOOL2) {
|
|
111
|
+
skipped.add(block.id);
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
if (call !== undefined) {
|
|
115
|
+
claude.set(block.id, call.id);
|
|
116
|
+
return [{ type: "tool_use", id: call.id, name: call.name, input: call.input }];
|
|
117
|
+
}
|
|
118
|
+
if (message.provider === CLAUDE_CODE_PROVIDER2) {
|
|
119
|
+
claude.set(block.id, block.id);
|
|
120
|
+
return [
|
|
121
|
+
{
|
|
122
|
+
type: "tool_use",
|
|
123
|
+
id: block.id,
|
|
124
|
+
name: `${NYTE_TOOL_PREFIX2}${block.name}`,
|
|
125
|
+
input: block.arguments
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
foreign.set(block.id, block.name);
|
|
130
|
+
return [{ type: "text", text: `[${block.name}]
|
|
131
|
+
${JSON.stringify(block.arguments)}` }];
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
closeCalls();
|
|
135
|
+
return params.map((param) => param.role === "user" && Array.isArray(param.content) ? {
|
|
136
|
+
...param,
|
|
137
|
+
content: [
|
|
138
|
+
...param.content.filter((block) => block.type === "tool_result"),
|
|
139
|
+
...param.content.filter((block) => block.type !== "tool_result")
|
|
140
|
+
]
|
|
141
|
+
} : param);
|
|
142
|
+
}
|
|
143
|
+
function sessionEntries2(messages, input) {
|
|
144
|
+
const timestamp = new Date().toISOString();
|
|
145
|
+
let parentUuid = null;
|
|
146
|
+
return toParams(messages, input.model).map((param) => {
|
|
147
|
+
const uuid = randomUUID();
|
|
148
|
+
const entry = {
|
|
149
|
+
type: param.role,
|
|
150
|
+
uuid,
|
|
151
|
+
parentUuid,
|
|
152
|
+
sessionId: input.session,
|
|
153
|
+
timestamp,
|
|
154
|
+
isSidechain: false,
|
|
155
|
+
userType: "external",
|
|
156
|
+
cwd: input.cwd,
|
|
157
|
+
message: param.role === "user" ? param : {
|
|
158
|
+
id: `msg_${uuid.replaceAll("-", "")}`,
|
|
159
|
+
type: "message",
|
|
160
|
+
role: "assistant",
|
|
161
|
+
model: input.model,
|
|
162
|
+
content: param.content,
|
|
163
|
+
stop_reason: null,
|
|
164
|
+
stop_sequence: null,
|
|
165
|
+
usage: { input_tokens: 0, output_tokens: 0 }
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
parentUuid = uuid;
|
|
169
|
+
return entry;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function flatPrompt2(messages) {
|
|
173
|
+
const turns = messages.filter((message) => message.role !== "system");
|
|
174
|
+
if (turns.length === 1 && turns[0]?.role === "user")
|
|
175
|
+
return text(turns[0].content);
|
|
176
|
+
return turns.map((message) => {
|
|
177
|
+
if (message.role === "assistant")
|
|
178
|
+
return `Assistant:
|
|
179
|
+
${message.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("")}`;
|
|
180
|
+
if (message.role === "toolResult")
|
|
181
|
+
return `Tool result (${message.toolName}):
|
|
182
|
+
${text(message.content)}`;
|
|
183
|
+
return message.role === "user" ? `User:
|
|
184
|
+
${text(message.content)}` : "";
|
|
185
|
+
}).join(`
|
|
186
|
+
|
|
187
|
+
`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { mirrorArguments3, userBlocks3, messageKey3, sessionEntries2, flatPrompt2 };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
answerInput2,
|
|
3
|
+
questionOutput2,
|
|
4
|
+
questionParameters2,
|
|
5
|
+
question3
|
|
6
|
+
} from "./billing-6z2kgtyt.js";
|
|
7
|
+
|
|
8
|
+
// src/question/question.ts
|
|
9
|
+
import { definePart, dev } from "@nyte-ai/core";
|
|
10
|
+
import { SdkError } from "@nyte-ai/schema";
|
|
11
|
+
function normalizeAnswers(items, supplied) {
|
|
12
|
+
if (supplied.length !== items.length)
|
|
13
|
+
throw new SdkError("invalid", "Submit one answer list for each question.");
|
|
14
|
+
return items.map((item, index) => {
|
|
15
|
+
const selected = supplied[index].map((answer) => answer.trim());
|
|
16
|
+
if (selected.some((answer) => answer === ""))
|
|
17
|
+
throw new SdkError("invalid", "Answers cannot be blank.");
|
|
18
|
+
if (!item.multiple && selected.length > 1)
|
|
19
|
+
throw new SdkError("invalid", "This question accepts one answer.");
|
|
20
|
+
if (new Set(selected).size !== selected.length)
|
|
21
|
+
throw new SdkError("invalid", "Choose each answer only once.");
|
|
22
|
+
return item.multiple ? selected.toSorted() : selected;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
var handlers = {
|
|
26
|
+
async answer(input, context) {
|
|
27
|
+
let accepted = false;
|
|
28
|
+
const outcome = await context.part.update((current) => {
|
|
29
|
+
const normalized = normalizeAnswers(current.questions, input.answers);
|
|
30
|
+
accepted = current.answers === null || JSON.stringify(current.answers) === JSON.stringify(normalized);
|
|
31
|
+
return current.answers === null ? { ...current, answers: normalized } : current;
|
|
32
|
+
});
|
|
33
|
+
if (outcome.kind !== "updated")
|
|
34
|
+
throw new Error(`The questions could not be answered: ${outcome.kind}.`);
|
|
35
|
+
if (!accepted)
|
|
36
|
+
throw new SdkError("invalid", "These questions were already answered.");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var question2 = definePart({
|
|
40
|
+
...question3,
|
|
41
|
+
onAction: (action, input, context) => handlers[action](input, context)
|
|
42
|
+
});
|
|
43
|
+
var ask = {
|
|
44
|
+
name: "question",
|
|
45
|
+
description: "Ask the user one or more questions and wait for their answers. Give each option a short label and a description. Use multiple when several choices may apply. The user can also write their own answer.",
|
|
46
|
+
parameters: questionParameters2,
|
|
47
|
+
output: questionOutput2,
|
|
48
|
+
class: (args) => ({
|
|
49
|
+
kind: "custom",
|
|
50
|
+
label: args.questions.map((item) => item.header).join(", ")
|
|
51
|
+
}),
|
|
52
|
+
effects: "none",
|
|
53
|
+
approval: "never",
|
|
54
|
+
replay: "safe",
|
|
55
|
+
async execute(args, invocation) {
|
|
56
|
+
for (const item of args.questions) {
|
|
57
|
+
if (new Set(item.options.map((option) => option.label.trim())).size !== item.options.length)
|
|
58
|
+
throw new SdkError("invalid", "Question option labels must be distinct.");
|
|
59
|
+
}
|
|
60
|
+
const part = await invocation.session.parts.create(question2, {
|
|
61
|
+
state: { ...args, answers: null },
|
|
62
|
+
placement: { kind: "modal" }
|
|
63
|
+
});
|
|
64
|
+
dev("question", "asked", { call: invocation.call, part: part.id });
|
|
65
|
+
const outcome = await invocation.wait({ kind: "part", part: part.id });
|
|
66
|
+
const checked = outcome.kind === "part" && outcome.answer?.action === "answer" ? await answerInput2["~standard"].validate(outcome.answer.input) : undefined;
|
|
67
|
+
const reply = checked !== undefined && checked.issues === undefined ? normalizeAnswers(args.questions, checked.value.answers) : null;
|
|
68
|
+
return {
|
|
69
|
+
content: [
|
|
70
|
+
{
|
|
71
|
+
kind: "text",
|
|
72
|
+
text: reply === null ? "The user did not answer. Continue with your best judgment and say what you assumed." : args.questions.map((item, index) => `${item.question}: ${reply[index].join(", ") || "Unanswered"}`).join(`
|
|
73
|
+
`)
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
output: { answers: reply },
|
|
77
|
+
parts: [part.id]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var question_default = {
|
|
82
|
+
id: "question",
|
|
83
|
+
contribute: { parts: [question2], tools: [ask] }
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export { question2, question_default };
|