@agentsky/sky 0.2.1 → 2.3.0
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/{chunk-L5LLCKZW.js → chunk-2KQLWHHC.js} +8827 -2129
- package/dist/index.d.ts +1 -0
- package/dist/index.js +753 -226
- package/dist/products.d.ts +585 -0
- package/dist/products.js +207 -0
- package/dist/src-EGXYUSME.js +281 -0
- package/package.json +21 -6
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-NLEDGUN7.js +0 -39
- package/dist/config-HRDRNTUU.js +0 -17
- package/dist/src-Y2XOFL3Z.js +0 -175
package/dist/src-Y2XOFL3Z.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
external_exports,
|
|
3
|
-
messagePartSchema
|
|
4
|
-
} from "./chunk-L5LLCKZW.js";
|
|
5
|
-
import "./chunk-MLKGABMK.js";
|
|
6
|
-
|
|
7
|
-
// ../../packages/chat/src/stream.ts
|
|
8
|
-
async function* parseSseStream(body) {
|
|
9
|
-
const reader = body.getReader();
|
|
10
|
-
const decoder = new TextDecoder();
|
|
11
|
-
let buffer = "";
|
|
12
|
-
try {
|
|
13
|
-
while (true) {
|
|
14
|
-
const { done, value } = await reader.read();
|
|
15
|
-
if (done) break;
|
|
16
|
-
buffer += decoder.decode(value, { stream: true });
|
|
17
|
-
let sep;
|
|
18
|
-
while ((sep = buffer.match(/\r?\n\r?\n/)) && sep.index !== void 0) {
|
|
19
|
-
const raw = buffer.slice(0, sep.index);
|
|
20
|
-
buffer = buffer.slice(sep.index + sep[0].length);
|
|
21
|
-
const frame = { data: "" };
|
|
22
|
-
const dataLines = [];
|
|
23
|
-
for (const line of raw.split(/\r?\n/)) {
|
|
24
|
-
if (!line || line.startsWith(":")) continue;
|
|
25
|
-
const colon = line.indexOf(":");
|
|
26
|
-
const field = colon === -1 ? line : line.slice(0, colon);
|
|
27
|
-
const value2 = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
28
|
-
if (field === "id") frame.id = value2;
|
|
29
|
-
else if (field === "event") frame.event = value2;
|
|
30
|
-
else if (field === "data") dataLines.push(value2);
|
|
31
|
-
}
|
|
32
|
-
frame.data = dataLines.join("\n");
|
|
33
|
-
if (frame.id !== void 0 || frame.event !== void 0 || frame.data) yield frame;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} finally {
|
|
37
|
-
reader.releaseLock();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function* streamAgentEvents(baseUrl, options = {}) {
|
|
41
|
-
const headers = { accept: "text/event-stream" };
|
|
42
|
-
if (options.lastEventId) headers["last-event-id"] = options.lastEventId;
|
|
43
|
-
const res = await fetch(`${baseUrl}/stream`, { headers, signal: options.signal });
|
|
44
|
-
if (!res.ok) throw new Error(`pod stream failed ${res.status}: ${await res.text()}`);
|
|
45
|
-
if (!res.body) throw new Error("pod stream returned no body");
|
|
46
|
-
try {
|
|
47
|
-
for await (const frame of parseSseStream(res.body)) {
|
|
48
|
-
let payload = {};
|
|
49
|
-
try {
|
|
50
|
-
payload = frame.data ? JSON.parse(frame.data) : {};
|
|
51
|
-
} catch {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
yield {
|
|
55
|
-
id: frame.id ?? "",
|
|
56
|
-
type: frame.event ?? (typeof payload.type === "string" ? payload.type : "unknown"),
|
|
57
|
-
detail: payload.detail ?? null,
|
|
58
|
-
data: payload.data ?? payload,
|
|
59
|
-
created_at: payload.created_at
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (!(error instanceof DOMException && error.name === "AbortError")) throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ../../packages/chat/src/index.ts
|
|
68
|
-
var chatPlatformSchema = external_exports.enum(["telegram", "slack", "discord", "whatsapp", "web"]);
|
|
69
|
-
var chatProxyRequestSchema = external_exports.object({
|
|
70
|
-
source: external_exports.enum(["web", "gateway", "actl", "internal"]).default("internal"),
|
|
71
|
-
mode: external_exports.enum(["accepted", "wait"]).default("accepted"),
|
|
72
|
-
userId: external_exports.string().min(1).optional(),
|
|
73
|
-
surface: external_exports.object({
|
|
74
|
-
platform: chatPlatformSchema,
|
|
75
|
-
conversationKey: external_exports.string().min(1),
|
|
76
|
-
platformIdentity: external_exports.string().optional(),
|
|
77
|
-
eventId: external_exports.string().optional()
|
|
78
|
-
}).optional(),
|
|
79
|
-
parts: external_exports.array(messagePartSchema).min(1),
|
|
80
|
-
timeoutMs: external_exports.number().int().positive().max(9e5).optional(),
|
|
81
|
-
metadata: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
82
|
-
/** The inbound message's ledger id (uiMessageId) when the caller persisted it
|
|
83
|
-
* at its own ingress: the proxy echoes it as the stream frame's messageId so
|
|
84
|
-
* consumers dedup the live echo against ledger catch-up. */
|
|
85
|
-
inboundMessageId: external_exports.string().min(1).max(160).optional()
|
|
86
|
-
});
|
|
87
|
-
async function postTurn(baseUrl, body, options = {}) {
|
|
88
|
-
const timeoutMs = options.timeoutMs ?? 2e4;
|
|
89
|
-
const retryDelayMs = options.retryDelayMs ?? 4e3;
|
|
90
|
-
const deadline = Date.now() + timeoutMs;
|
|
91
|
-
let res;
|
|
92
|
-
let lastError;
|
|
93
|
-
const headers = { "content-type": "application/json" };
|
|
94
|
-
if (options.idempotencyKey) headers["idempotency-key"] = options.idempotencyKey;
|
|
95
|
-
while (Date.now() < deadline) {
|
|
96
|
-
try {
|
|
97
|
-
res = await fetch(`${baseUrl}/messages`, {
|
|
98
|
-
method: "POST",
|
|
99
|
-
headers,
|
|
100
|
-
body: JSON.stringify(body),
|
|
101
|
-
signal: AbortSignal.timeout(Math.max(1, deadline - Date.now()))
|
|
102
|
-
});
|
|
103
|
-
lastError = void 0;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
lastError = error;
|
|
106
|
-
res = void 0;
|
|
107
|
-
}
|
|
108
|
-
if (res && res.ok) break;
|
|
109
|
-
if (res && res.status !== 502 && res.status !== 503 && res.status !== 504) break;
|
|
110
|
-
const remaining = deadline - Date.now();
|
|
111
|
-
if (remaining <= 0) break;
|
|
112
|
-
await new Promise((r) => setTimeout(r, Math.min(retryDelayMs, remaining)));
|
|
113
|
-
}
|
|
114
|
-
if (!res) {
|
|
115
|
-
const suffix = lastError instanceof Error ? `: ${lastError.message}` : "";
|
|
116
|
-
throw new Error(`pod unreachable${suffix}`);
|
|
117
|
-
}
|
|
118
|
-
if (!res.ok) throw new Error(`pod message failed ${res.status}: ${await res.text()}`);
|
|
119
|
-
}
|
|
120
|
-
async function sendAgentTurn(baseUrl, parts, options = {}) {
|
|
121
|
-
await postTurn(baseUrl, { parts }, options);
|
|
122
|
-
}
|
|
123
|
-
function textFromParts(parts) {
|
|
124
|
-
return parts.map((part) => part.type === "text" ? part.text : "").filter(Boolean).join(" ").trim();
|
|
125
|
-
}
|
|
126
|
-
async function postChatProxy(args) {
|
|
127
|
-
const url = new URL(
|
|
128
|
-
`/api/v1/sessions/${encodeURIComponent(args.agentRouteId)}/messages`,
|
|
129
|
-
normalizeBaseUrl(args.baseUrl)
|
|
130
|
-
);
|
|
131
|
-
const headers = {
|
|
132
|
-
authorization: `Bearer ${args.token}`,
|
|
133
|
-
"content-type": "application/json"
|
|
134
|
-
};
|
|
135
|
-
if (args.idempotencyKey) headers["idempotency-key"] = args.idempotencyKey;
|
|
136
|
-
const request = args.request;
|
|
137
|
-
const body = {
|
|
138
|
-
parts: request.parts,
|
|
139
|
-
mode: request.mode,
|
|
140
|
-
timeoutMs: request.timeoutMs,
|
|
141
|
-
messageId: request.inboundMessageId,
|
|
142
|
-
onBehalfOf: {
|
|
143
|
-
userId: request.userId,
|
|
144
|
-
surface: request.surface ? {
|
|
145
|
-
platform: request.surface.platform,
|
|
146
|
-
conversationKey: request.surface.conversationKey,
|
|
147
|
-
eventId: request.surface.eventId
|
|
148
|
-
} : request.source === "web" ? { platform: "web", conversationKey: "direct-chat" } : void 0
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const response = await fetch(url, {
|
|
152
|
-
method: "POST",
|
|
153
|
-
headers,
|
|
154
|
-
body: JSON.stringify(body),
|
|
155
|
-
signal: AbortSignal.timeout(args.timeoutMs ?? args.request.timeoutMs ?? 95e3)
|
|
156
|
-
});
|
|
157
|
-
const data = await response.json().catch(() => ({}));
|
|
158
|
-
if (!response.ok) {
|
|
159
|
-
const message = typeof data.error === "string" ? data.error : data.error?.message;
|
|
160
|
-
throw new Error(message ?? `chat proxy failed ${response.status}`);
|
|
161
|
-
}
|
|
162
|
-
return data;
|
|
163
|
-
}
|
|
164
|
-
function normalizeBaseUrl(value) {
|
|
165
|
-
return value.endsWith("/") ? value : `${value}/`;
|
|
166
|
-
}
|
|
167
|
-
export {
|
|
168
|
-
chatPlatformSchema,
|
|
169
|
-
chatProxyRequestSchema,
|
|
170
|
-
parseSseStream,
|
|
171
|
-
postChatProxy,
|
|
172
|
-
sendAgentTurn,
|
|
173
|
-
streamAgentEvents,
|
|
174
|
-
textFromParts
|
|
175
|
-
};
|