@anchrd/colab-sdk 0.1.51 → 0.1.53
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/dist/action-blocks/action-blocks.d.ts +63 -0
- package/dist/action-blocks/action-blocks.js +47 -0
- package/dist/actions/actions.d.ts +31 -0
- package/dist/actions/actions.js +11 -1
- package/dist/conversations/conversations.d.ts +574 -0
- package/dist/conversations/conversations.js +196 -0
- package/dist/dictations/dictations.d.ts +8 -0
- package/dist/dictations/dictations.js +12 -0
- package/dist/error/error.d.ts +2 -0
- package/dist/error/error.js +50 -3
- package/dist/flows/flow-runs.d.ts +2313 -0
- package/dist/flows/flow-runs.js +424 -0
- package/dist/flows/flows.d.ts +2761 -0
- package/dist/flows/flows.js +471 -0
- package/dist/goals/goals.d.ts +23 -0
- package/dist/grammar/grammar.d.ts +4 -0
- package/dist/grammar/grammar.js +15 -0
- package/dist/machines/machines.d.ts +1 -0
- package/dist/messages/messages.d.ts +69 -1
- package/dist/messages/messages.js +91 -7
- package/dist/nodes/nodes.d.ts +9 -1
- package/dist/nodes/nodes.js +13 -1
- package/dist/operators/operators.d.ts +89 -137
- package/dist/operators/operators.js +19 -43
- package/dist/relations/relations.d.ts +2 -0
- package/dist/schedule/schedule.d.ts +1 -0
- package/dist/schedule/schedule.js +1 -1
- package/dist/sdk.d.ts +7 -2
- package/dist/sdk.js +7 -2
- package/dist/tree-order/tree-order.d.ts +1 -1
- package/dist/tree-order/tree-order.js +1 -0
- package/dist/users/users.d.ts +5 -0
- package/dist/users/users.js +3 -0
- package/dist/written/written.d.ts +8 -0
- package/dist/written/written.js +10 -1
- package/package.json +1 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { idSchema } from "../ids/ids.js";
|
|
3
|
+
import { Flag, Limit } from "../list-input.js";
|
|
4
|
+
import { AttachmentId, attachmentMaxBytes, attachmentsMax, MessageAttachment, } from "../messages/messages.js";
|
|
5
|
+
import { NodeId } from "../nodes/nodes.js";
|
|
6
|
+
import { OperatorRunTokens } from "../operators/operators.js";
|
|
7
|
+
import { IdempotencyKey } from "../primitives/primitives.js";
|
|
8
|
+
import { UserId } from "../users/users.js";
|
|
9
|
+
// A person's conversation with one of their personal Operators (E267, #1212, Funktionen ›
|
|
10
|
+
// KI-Chat). At most one is open per person; "Neuer Chat" archives it, and an archived one is never
|
|
11
|
+
// opened again: it is read and searched as context, by its person only, never by an admin.
|
|
12
|
+
//
|
|
13
|
+
// While it is open its history lives in one Durable Object per conversation, which holds the
|
|
14
|
+
// WebSocket of every browser of its person; archiving moves the history into `OPERATOR_DB`.
|
|
15
|
+
// The socket's protocol stands here, so the UI (#1213) and the runtimes (#1214) build against it.
|
|
16
|
+
export const ConversationId = idSchema("conversation").describe("The conversation, `conversation_…`.");
|
|
17
|
+
export const ConversationMessageId = idSchema("message").describe("A message of the conversation, `message_…`.");
|
|
18
|
+
export const ConversationStepId = idSchema("step");
|
|
19
|
+
// The title from the first question, cut; the person may change it.
|
|
20
|
+
export const conversationTitleMax = 120;
|
|
21
|
+
// One message of the person.
|
|
22
|
+
export const conversationTextMax = 20_000;
|
|
23
|
+
export const ConversationStatus = z.enum(["open", "archived"]);
|
|
24
|
+
// One tool call of the Operator during an answer. It may carry names (`name`: the node, the board,
|
|
25
|
+
// the query it touched): only its person ever sees a conversation.
|
|
26
|
+
export const ConversationStep = z.object({
|
|
27
|
+
stepId: ConversationStepId,
|
|
28
|
+
// The tool as `/mcp` names it (`intelligence_board_create`), or the runtime's own (`Read`).
|
|
29
|
+
tool: z.string().max(200),
|
|
30
|
+
// What it touched, in a few words; null where the call names nothing.
|
|
31
|
+
name: z.string().max(200).nullable(),
|
|
32
|
+
// The node it touched (#1222, E271): its resource's id in the input (`skillId` of
|
|
33
|
+
// `intelligence_skill_update`). The browser names it only where its person may read it. Missing
|
|
34
|
+
// on a step stored before.
|
|
35
|
+
nodeId: NodeId.nullable().optional(),
|
|
36
|
+
status: z.enum(["running", "done", "failed"]),
|
|
37
|
+
startedAt: z.iso.datetime(),
|
|
38
|
+
endedAt: z.iso.datetime().nullable(),
|
|
39
|
+
});
|
|
40
|
+
// `answering` while the Operator still writes it; `aborted` when its person stopped it, `failed`
|
|
41
|
+
// when the runtime gave up (`detail` says why).
|
|
42
|
+
export const ConversationMessageStatus = z.enum(["done", "answering", "aborted", "failed"]);
|
|
43
|
+
export const ConversationMessage = z.object({
|
|
44
|
+
messageId: ConversationMessageId,
|
|
45
|
+
role: z.enum(["person", "operator"]),
|
|
46
|
+
text: z.string(),
|
|
47
|
+
// Only the Operator's messages carry steps, in the order they began.
|
|
48
|
+
steps: z.array(ConversationStep),
|
|
49
|
+
status: ConversationMessageStatus,
|
|
50
|
+
detail: z.string().nullable(),
|
|
51
|
+
// The person's own id for a message it sent (`send.clientId`), so a browser matches its echo.
|
|
52
|
+
clientId: z.string().nullable(),
|
|
53
|
+
createdAt: z.iso.datetime(),
|
|
54
|
+
// What the answer cost and counted; null on the person's messages and where nothing was counted.
|
|
55
|
+
costUsd: z.number().min(0).nullable(),
|
|
56
|
+
tokens: OperatorRunTokens.nullable(),
|
|
57
|
+
// The files the person sent with a question (#1213, E267), shaped like a chat message's (E265);
|
|
58
|
+
// absent on every other message and on a message from before.
|
|
59
|
+
attachments: z.array(MessageAttachment).optional(),
|
|
60
|
+
});
|
|
61
|
+
export const Conversation = z.object({
|
|
62
|
+
conversationId: ConversationId,
|
|
63
|
+
// The person it belongs to.
|
|
64
|
+
userId: UserId,
|
|
65
|
+
// The personal Operator it runs with, and its name and model at this moment.
|
|
66
|
+
machineId: UserId,
|
|
67
|
+
operator: z.object({ name: z.string(), model: z.string() }).nullable(),
|
|
68
|
+
title: z.string(),
|
|
69
|
+
status: ConversationStatus,
|
|
70
|
+
messageCount: z.int().min(0),
|
|
71
|
+
// Summed over every answer, like a run's.
|
|
72
|
+
costUsd: z.number().min(0).nullable(),
|
|
73
|
+
tokens: OperatorRunTokens,
|
|
74
|
+
createdAt: z.iso.datetime(),
|
|
75
|
+
updatedAt: z.iso.datetime(),
|
|
76
|
+
archivedAt: z.iso.datetime().nullable(),
|
|
77
|
+
rev: z.int().min(1),
|
|
78
|
+
});
|
|
79
|
+
// A hit of the search: the conversation and the passage that matched.
|
|
80
|
+
export const ConversationHit = Conversation.extend({ excerpt: z.string().nullable() });
|
|
81
|
+
// ---------------------------------------------------------------------------------------------
|
|
82
|
+
// The socket: `GET /live/conversations/:conversationId` with `Upgrade: websocket`, only for the
|
|
83
|
+
// conversation's own person (anybody else, an admin too, gets the 404 before the upgrade). One
|
|
84
|
+
// JSON object per frame.
|
|
85
|
+
// The browser to the conversation.
|
|
86
|
+
export const ConversationClientMessage = z.discriminatedUnion("type", [
|
|
87
|
+
// A question. Refused with `error` `conflict` while an answer is still being written. It may carry
|
|
88
|
+
// up to ten files uploaded into this conversation (`operator_conversation_attachment_create`,
|
|
89
|
+
// #1213); with them its text may be empty.
|
|
90
|
+
z
|
|
91
|
+
.strictObject({
|
|
92
|
+
type: z.literal("send"),
|
|
93
|
+
clientId: z.string().min(1).max(64),
|
|
94
|
+
text: z.string().trim().max(conversationTextMax),
|
|
95
|
+
attachments: z.array(AttachmentId).max(attachmentsMax).optional(),
|
|
96
|
+
})
|
|
97
|
+
.refine((frame) => frame.text !== "" || (frame.attachments?.length ?? 0) > 0, {
|
|
98
|
+
message: "A question needs text or an attachment.",
|
|
99
|
+
}),
|
|
100
|
+
// Stops the answer being written; what it wrote so far stays, as `aborted`.
|
|
101
|
+
z.strictObject({ type: z.literal("abort") }),
|
|
102
|
+
]);
|
|
103
|
+
// The conversation to the browser.
|
|
104
|
+
export const ConversationServerMessage = z.discriminatedUnion("type", [
|
|
105
|
+
// The whole state, first on every connect: a browser that joins in the middle of an answer gets
|
|
106
|
+
// the answer as far as it is (`status: "answering"`) and the deltas from there.
|
|
107
|
+
z.object({
|
|
108
|
+
type: z.literal("state"),
|
|
109
|
+
conversation: Conversation,
|
|
110
|
+
messages: z.array(ConversationMessage),
|
|
111
|
+
}),
|
|
112
|
+
// A message of the person, whole (with its `clientId`), to every browser of the person.
|
|
113
|
+
z.object({ type: z.literal("message"), message: ConversationMessage }),
|
|
114
|
+
// The Operator begins to answer: its message with `status: "answering"`.
|
|
115
|
+
z.object({ type: z.literal("answer.start"), message: ConversationMessage }),
|
|
116
|
+
// The next piece of the answer's text, appended to `text`.
|
|
117
|
+
z.object({
|
|
118
|
+
type: z.literal("answer.text"),
|
|
119
|
+
messageId: ConversationMessageId,
|
|
120
|
+
delta: z.string(),
|
|
121
|
+
}),
|
|
122
|
+
// A step began (`running`) or ended (`done`, `failed`): replace the step of the same `stepId`.
|
|
123
|
+
z.object({
|
|
124
|
+
type: z.literal("answer.step"),
|
|
125
|
+
messageId: ConversationMessageId,
|
|
126
|
+
step: ConversationStep,
|
|
127
|
+
}),
|
|
128
|
+
// The answer is over, whole, with its status, cost and tokens.
|
|
129
|
+
z.object({ type: z.literal("answer.end"), message: ConversationMessage }),
|
|
130
|
+
// The conversation changed (title, cost, count).
|
|
131
|
+
z.object({ type: z.literal("conversation"), conversation: Conversation }),
|
|
132
|
+
// A frame that was refused; the socket stays open.
|
|
133
|
+
z.object({
|
|
134
|
+
type: z.literal("error"),
|
|
135
|
+
code: z.enum(["invalid", "conflict", "unavailable"]),
|
|
136
|
+
message: z.string(),
|
|
137
|
+
}),
|
|
138
|
+
]);
|
|
139
|
+
// The close codes of the socket (4000 to 4999 are the application's own); the reason is the word.
|
|
140
|
+
export const conversationClose = {
|
|
141
|
+
// "Neuer Chat" archived it: the browser opens the new one.
|
|
142
|
+
archived: { code: 4409, reason: "archived" },
|
|
143
|
+
// Its person may no longer use it (the Operator is gone, the person locked).
|
|
144
|
+
gone: { code: 4404, reason: "gone" },
|
|
145
|
+
};
|
|
146
|
+
// ---------------------------------------------------------------------------------------------
|
|
147
|
+
// The tools `operator_conversation_*`: always the caller's own conversations, in admin mode too.
|
|
148
|
+
export const ConversationListInput = z.strictObject({
|
|
149
|
+
query: z
|
|
150
|
+
.string()
|
|
151
|
+
.trim()
|
|
152
|
+
.min(2)
|
|
153
|
+
.max(200)
|
|
154
|
+
.optional()
|
|
155
|
+
.describe("Search the archived conversations by words and meaning; the hits come with the passage that matched."),
|
|
156
|
+
archived: Flag.optional().describe("true: only the archived conversations; false: only the open one. Leaving it out lists both."),
|
|
157
|
+
cursor: z.string().max(200).optional(),
|
|
158
|
+
limit: Limit.optional(),
|
|
159
|
+
});
|
|
160
|
+
export const ConversationGetInput = z.strictObject({ conversationId: ConversationId });
|
|
161
|
+
export const ConversationGetAnswer = Conversation.extend({
|
|
162
|
+
messages: z.array(ConversationMessage),
|
|
163
|
+
});
|
|
164
|
+
export const ConversationCreateInput = z.strictObject({
|
|
165
|
+
machineId: UserId.optional().describe("The personal Operator to talk with, `user_…`; leaving it out takes the one of the open conversation, else the first."),
|
|
166
|
+
});
|
|
167
|
+
export const ConversationUpdateInput = z.strictObject({
|
|
168
|
+
conversationId: ConversationId,
|
|
169
|
+
rev: z.int().min(1).describe("The rev the conversation was read with."),
|
|
170
|
+
title: z.string().trim().min(1).max(conversationTitleMax).optional(),
|
|
171
|
+
machineId: UserId.optional().describe("Another of the person's personal Operators for the open conversation, only while it has no message yet; once it has one, its Operator stays (conflict) and a new conversation takes the other."),
|
|
172
|
+
});
|
|
173
|
+
export const ConversationArchiveInput = z.strictObject({ conversationId: ConversationId });
|
|
174
|
+
// A file for the open conversation's next question (#1213, E267): uploaded first, then named by the
|
|
175
|
+
// question's `send.attachments`. Only the conversation's person, never an Operator.
|
|
176
|
+
const attachmentMaxBase64 = Math.ceil(attachmentMaxBytes / 3) * 4;
|
|
177
|
+
export const ConversationAttachmentCreateInput = z.strictObject({
|
|
178
|
+
conversationId: ConversationId.describe("Your open conversation, `conversation_…`."),
|
|
179
|
+
name: z.string().trim().min(1).max(255).describe("The file's name, e.g. `angebot.pdf`."),
|
|
180
|
+
mediaType: z
|
|
181
|
+
.string()
|
|
182
|
+
.trim()
|
|
183
|
+
.min(1)
|
|
184
|
+
.max(255)
|
|
185
|
+
.describe("The file's media type, e.g. `image/png` or `application/pdf`."),
|
|
186
|
+
content: z
|
|
187
|
+
.base64()
|
|
188
|
+
.max(attachmentMaxBase64, "An attachment holds at most 20 MB.")
|
|
189
|
+
.describe("The file's bytes as Base64, at most 20 MB after decoding."),
|
|
190
|
+
idempotencyKey: IdempotencyKey,
|
|
191
|
+
});
|
|
192
|
+
export const ConversationPurgeInput = z.strictObject({ conversationId: ConversationId });
|
|
193
|
+
export const ConversationListAnswer = z.object({
|
|
194
|
+
items: z.array(ConversationHit),
|
|
195
|
+
nextCursor: z.string().nullable(),
|
|
196
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const dictationSampleRate = 16000;
|
|
3
|
+
export declare const dictationMaxSeconds = 30;
|
|
4
|
+
export declare const dictationMaxBytes: number;
|
|
5
|
+
export declare const DictationCreateOutput: z.ZodObject<{
|
|
6
|
+
text: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type DictationCreateOutput = z.infer<typeof DictationCreateOutput>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// One dictated sentence (#1211, E266): the browser cuts the speech at its pauses and sends each
|
|
3
|
+
// sentence alone as WAV, 16-bit PCM, mono, 16 kHz, the format the speech models take without a
|
|
4
|
+
// conversion. The door `POST /api/intelligence/dictations` answers its text; nothing is stored.
|
|
5
|
+
export const dictationSampleRate = 16_000;
|
|
6
|
+
// Whisper reads 30 seconds at a time; a longer "sentence" is no pause the browser found, and is
|
|
7
|
+
// refused rather than cut.
|
|
8
|
+
export const dictationMaxSeconds = 30;
|
|
9
|
+
// The bytes of 30 seconds, with room for the head and a chunk before the sound (a `LIST` chunk, as
|
|
10
|
+
// macOS writes it): the seconds in the head are the real limit.
|
|
11
|
+
export const dictationMaxBytes = 4096 + dictationMaxSeconds * dictationSampleRate * 2;
|
|
12
|
+
export const DictationCreateOutput = z.object({ text: z.string() });
|
package/dist/error/error.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const ErrorCurrent: z.ZodObject<{
|
|
|
23
23
|
gadgetId: z.ZodOptional<z.ZodTemplateLiteral<`node_${string}`>>;
|
|
24
24
|
nodeId: z.ZodOptional<z.ZodTemplateLiteral<`node_${string}`>>;
|
|
25
25
|
machineId: z.ZodOptional<z.ZodTemplateLiteral<`user_${string}`>>;
|
|
26
|
+
conversationId: z.ZodOptional<z.ZodTemplateLiteral<`conversation_${string}`>>;
|
|
26
27
|
connectorId: z.ZodOptional<z.ZodString>;
|
|
27
28
|
rev: z.ZodNumber;
|
|
28
29
|
savedBy: z.ZodOptional<z.ZodObject<{
|
|
@@ -60,6 +61,7 @@ export declare const ErrorResponse: z.ZodObject<{
|
|
|
60
61
|
gadgetId: z.ZodOptional<z.ZodTemplateLiteral<`node_${string}`>>;
|
|
61
62
|
nodeId: z.ZodOptional<z.ZodTemplateLiteral<`node_${string}`>>;
|
|
62
63
|
machineId: z.ZodOptional<z.ZodTemplateLiteral<`user_${string}`>>;
|
|
64
|
+
conversationId: z.ZodOptional<z.ZodTemplateLiteral<`conversation_${string}`>>;
|
|
63
65
|
connectorId: z.ZodOptional<z.ZodString>;
|
|
64
66
|
rev: z.ZodNumber;
|
|
65
67
|
savedBy: z.ZodOptional<z.ZodObject<{
|
package/dist/error/error.js
CHANGED
|
@@ -34,6 +34,8 @@ export const ErrorCurrent = z.strictObject({
|
|
|
34
34
|
gadgetId: NodeRef.optional(),
|
|
35
35
|
nodeId: NodeRef.optional(),
|
|
36
36
|
machineId: idSchema("user").optional(),
|
|
37
|
+
// A person's conversation with a personal Operator (#1212).
|
|
38
|
+
conversationId: idSchema("conversation").optional(),
|
|
37
39
|
// A built connector's id (#894), `github`.
|
|
38
40
|
connectorId: z.string().optional(),
|
|
39
41
|
rev: z.number().int(),
|
|
@@ -167,9 +169,47 @@ const dotted = (path) => path.length === 0 ? "its top level" : path.map(String).
|
|
|
167
169
|
// `invalid` for an input its tool's schema refused (#678), at `/api` and `/mcp` alike: each issue
|
|
168
170
|
// with the field's path, Zod's sentence and the form the field expects; a key the schema does not
|
|
169
171
|
// know names the fields that are there instead.
|
|
172
|
+
// The largest `expected` an issue carries (#1230): the schema of a whole union of actions ran to
|
|
173
|
+
// 86 KB, 21,000 tokens for one wrong call. Past this the sentence says enough.
|
|
174
|
+
const maxExpected = 800;
|
|
175
|
+
// A union of objects told apart by `type` (#1230): the branch whose `type` fit is the one meant, so
|
|
176
|
+
// its issues stand for the union's; a `type` no branch knows is one issue naming the kinds. Any
|
|
177
|
+
// other union stays as it is.
|
|
178
|
+
function narrowed(issue) {
|
|
179
|
+
if (issue.code !== "invalid_union" || issue.errors.length === 0)
|
|
180
|
+
return [issue];
|
|
181
|
+
const typeIssue = (inner) => inner.path.length === 1 &&
|
|
182
|
+
inner.path[0] === "type" &&
|
|
183
|
+
(inner.code === "invalid_value" || inner.code === "invalid_union");
|
|
184
|
+
const named = issue.errors.some((branch) => branch.some(typeIssue));
|
|
185
|
+
if (!named)
|
|
186
|
+
return [issue];
|
|
187
|
+
const meant = issue.errors.find((branch) => !branch.some(typeIssue));
|
|
188
|
+
if (meant) {
|
|
189
|
+
return meant.flatMap((inner) => narrowed({ ...inner, path: [...issue.path, ...inner.path] }));
|
|
190
|
+
}
|
|
191
|
+
const kinds = [
|
|
192
|
+
...new Set(issue.errors.flatMap((branch) => branch.flatMap((inner) => {
|
|
193
|
+
if (!typeIssue(inner))
|
|
194
|
+
return [];
|
|
195
|
+
if (inner.code === "invalid_value")
|
|
196
|
+
return inner.values.map(String);
|
|
197
|
+
const options = inner.options;
|
|
198
|
+
return Array.isArray(options) ? options.map(String) : [];
|
|
199
|
+
}))),
|
|
200
|
+
];
|
|
201
|
+
return [
|
|
202
|
+
{
|
|
203
|
+
code: "custom",
|
|
204
|
+
path: [...issue.path, "type"],
|
|
205
|
+
message: `Unknown type; it is one of: ${kinds.join(", ")}.`,
|
|
206
|
+
input: undefined,
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
}
|
|
170
210
|
export function invalidInput(schema, error) {
|
|
171
211
|
const root = jsonSchemaOf(schema);
|
|
172
|
-
const issues = error.issues.map((issue) => {
|
|
212
|
+
const issues = error.issues.flatMap(narrowed).map((issue) => {
|
|
173
213
|
const path = issue.path.map((part) => (typeof part === "symbol" ? String(part) : part));
|
|
174
214
|
if (issue.code === "unrecognized_keys") {
|
|
175
215
|
const fields = root ? fieldsAt(root, path) : [];
|
|
@@ -180,8 +220,15 @@ export function invalidInput(schema, error) {
|
|
|
180
220
|
: issue.message,
|
|
181
221
|
};
|
|
182
222
|
}
|
|
183
|
-
const expected = root ? schemaAt(root, path) : undefined;
|
|
184
|
-
|
|
223
|
+
const expected = root && issue.code !== "custom" ? schemaAt(root, path) : undefined;
|
|
224
|
+
const fits = expected !== undefined && JSON.stringify(expected).length <= maxExpected;
|
|
225
|
+
// A missing field says so in one sentence (#1230); its form stands in `expected`.
|
|
226
|
+
const missing = issue.code === "invalid_type" && issue.message.endsWith("received undefined");
|
|
227
|
+
return {
|
|
228
|
+
path,
|
|
229
|
+
message: missing ? `${dotted(path)} is missing.` : issue.message,
|
|
230
|
+
...(fits && { expected }),
|
|
231
|
+
};
|
|
185
232
|
});
|
|
186
233
|
const places = [...new Set(issues.map((issue) => dotted(issue.path)))];
|
|
187
234
|
const hint = idKeyHint(root, error);
|