@percena/weft 0.4.0-next.7 → 0.4.0-next.9
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/chat.cjs +2 -2
- package/dist/chat.d.cts +0 -167
- package/dist/chat.d.ts +0 -167
- package/dist/chat.js +2 -2
- package/dist/index.cjs +23 -17
- package/dist/index.d.cts +51 -1774
- package/dist/index.d.ts +51 -1774
- package/dist/index.js +23 -17
- package/dist/providers-flitro.cjs +35 -29
- package/dist/providers-flitro.d.cts +51 -49
- package/dist/providers-flitro.d.ts +51 -49
- package/dist/providers-flitro.js +31 -25
- package/package.json +3 -3
package/dist/providers-flitro.js
CHANGED
|
@@ -223,13 +223,14 @@ function sortTimeline(timeline) {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
// ../packages/client/dist/index.js
|
|
226
|
-
var
|
|
226
|
+
var WeftHttpClient = class {
|
|
227
227
|
baseUrl;
|
|
228
228
|
timeout;
|
|
229
229
|
apiKey;
|
|
230
230
|
tenantId;
|
|
231
231
|
onTokenExpired;
|
|
232
232
|
token;
|
|
233
|
+
embedMode;
|
|
233
234
|
constructor(options) {
|
|
234
235
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
235
236
|
this.timeout = options.timeout ?? 3e4;
|
|
@@ -237,6 +238,11 @@ var FlitroHttpClient = class {
|
|
|
237
238
|
this.tenantId = options.tenantId ?? "";
|
|
238
239
|
this.token = options.token ?? "";
|
|
239
240
|
this.onTokenExpired = options.onTokenExpired;
|
|
241
|
+
this.embedMode = !!(this.token && !this.apiKey);
|
|
242
|
+
}
|
|
243
|
+
sessionPath(sessionId) {
|
|
244
|
+
const encoded = encodeURIComponent(sessionId);
|
|
245
|
+
return this.embedMode ? `/v1/embed/sessions/${encoded}` : `/v1/sessions/${encoded}`;
|
|
240
246
|
}
|
|
241
247
|
/** Current Authorization bearer (scoped token wins over apiKey). */
|
|
242
248
|
getBearerToken() {
|
|
@@ -268,7 +274,7 @@ var FlitroHttpClient = class {
|
|
|
268
274
|
});
|
|
269
275
|
}
|
|
270
276
|
async getSession(sessionId) {
|
|
271
|
-
return this.get(
|
|
277
|
+
return this.get(`${this.sessionPath(sessionId)}`);
|
|
272
278
|
}
|
|
273
279
|
async sendMessage(sessionId, message, options) {
|
|
274
280
|
const budget = options?.budget ? {
|
|
@@ -276,7 +282,7 @@ var FlitroHttpClient = class {
|
|
|
276
282
|
max_tokens: options.budget.maxTokens,
|
|
277
283
|
max_wall_time_sec: options.budget.maxWallTimeSec
|
|
278
284
|
} : void 0;
|
|
279
|
-
return this.post(
|
|
285
|
+
return this.post(`${this.sessionPath(sessionId)}/runs`, {
|
|
280
286
|
message,
|
|
281
287
|
model: options?.model,
|
|
282
288
|
skill_names: options?.skillNames,
|
|
@@ -299,13 +305,13 @@ var FlitroHttpClient = class {
|
|
|
299
305
|
}
|
|
300
306
|
async respondToPermission(sessionId, requestId, allowed, options) {
|
|
301
307
|
return this.post(
|
|
302
|
-
|
|
308
|
+
`${this.sessionPath(sessionId)}/permission-response`,
|
|
303
309
|
{ requestId, allowed, remember: options?.remember, text: options?.text, answer: options?.answer }
|
|
304
310
|
);
|
|
305
311
|
}
|
|
306
312
|
async patchSession(sessionId, patch) {
|
|
307
313
|
return this.patch(
|
|
308
|
-
|
|
314
|
+
`${this.sessionPath(sessionId)}`,
|
|
309
315
|
patch
|
|
310
316
|
);
|
|
311
317
|
}
|
|
@@ -317,12 +323,12 @@ var FlitroHttpClient = class {
|
|
|
317
323
|
if (afterSeq !== void 0) params.set("after_seq", String(afterSeq));
|
|
318
324
|
if (limit !== void 0) params.set("limit", String(limit));
|
|
319
325
|
const qs = params.toString();
|
|
320
|
-
const url =
|
|
326
|
+
const url = `${this.sessionPath(sessionId)}/timeline/fetch${qs ? `?${qs}` : ""}`;
|
|
321
327
|
return this.get(url);
|
|
322
328
|
}
|
|
323
329
|
/** Returns the SSE stream URL for a session's canonical timeline. */
|
|
324
330
|
sessionTimelineUrl(sessionId) {
|
|
325
|
-
return `${this.baseUrl}
|
|
331
|
+
return `${this.baseUrl}${this.sessionPath(sessionId)}/timeline`;
|
|
326
332
|
}
|
|
327
333
|
async get(path) {
|
|
328
334
|
return this.request("GET", path, void 0);
|
|
@@ -352,7 +358,7 @@ var FlitroHttpClient = class {
|
|
|
352
358
|
}
|
|
353
359
|
}
|
|
354
360
|
if (!response.ok) {
|
|
355
|
-
let errorMsg = `
|
|
361
|
+
let errorMsg = `Weft HTTP ${response.status}`;
|
|
356
362
|
try {
|
|
357
363
|
const errBody = await response.json();
|
|
358
364
|
if (errBody.error) errorMsg = `${errorMsg}: ${errBody.error}`;
|
|
@@ -366,7 +372,7 @@ var FlitroHttpClient = class {
|
|
|
366
372
|
}
|
|
367
373
|
}
|
|
368
374
|
};
|
|
369
|
-
var
|
|
375
|
+
var WeftSseTimelineStream = class {
|
|
370
376
|
listeners = /* @__PURE__ */ new Set();
|
|
371
377
|
eventSource = null;
|
|
372
378
|
disposed = false;
|
|
@@ -375,7 +381,7 @@ var FlitroSseTimelineStream = class {
|
|
|
375
381
|
// Native EventSource cannot set headers or observe HTTP status codes, so
|
|
376
382
|
// scoped tokens travel as a ?token= query param (re-read on every reconnect
|
|
377
383
|
// to pick up rotation); onTokenExpired is only actionable in the fetch-based
|
|
378
|
-
// stream, which is what
|
|
384
|
+
// stream, which is what createTimelineStream returns.
|
|
379
385
|
getBearerToken;
|
|
380
386
|
options;
|
|
381
387
|
constructor(options) {
|
|
@@ -463,7 +469,7 @@ var FlitroSseTimelineStream = class {
|
|
|
463
469
|
scheduleReconnect() {
|
|
464
470
|
if (this.disposed) return;
|
|
465
471
|
if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
|
|
466
|
-
this.emitError(new Error(`
|
|
472
|
+
this.emitError(new Error(`Weft SSE: max reconnect attempts (${this.options.maxReconnectAttempts}) reached`));
|
|
467
473
|
return;
|
|
468
474
|
}
|
|
469
475
|
this.reconnectAttempts++;
|
|
@@ -479,7 +485,7 @@ var FlitroSseTimelineStream = class {
|
|
|
479
485
|
}
|
|
480
486
|
}
|
|
481
487
|
};
|
|
482
|
-
var
|
|
488
|
+
var WeftFetchSseTimelineStream = class {
|
|
483
489
|
listeners = /* @__PURE__ */ new Set();
|
|
484
490
|
abortController = null;
|
|
485
491
|
connected = false;
|
|
@@ -552,7 +558,7 @@ var FlitroFetchSseTimelineStream = class {
|
|
|
552
558
|
if (fresh) this.tokenOverride = fresh;
|
|
553
559
|
}
|
|
554
560
|
if (!response.ok || !response.body) {
|
|
555
|
-
throw new Error(`
|
|
561
|
+
throw new Error(`Weft SSE: HTTP ${response.status}`);
|
|
556
562
|
}
|
|
557
563
|
this.reconnectAttempts = 0;
|
|
558
564
|
const reader = response.body.getReader();
|
|
@@ -587,7 +593,7 @@ var FlitroFetchSseTimelineStream = class {
|
|
|
587
593
|
scheduleReconnect() {
|
|
588
594
|
if (this.disposed) return;
|
|
589
595
|
if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
|
|
590
|
-
this.emitError(new Error(`
|
|
596
|
+
this.emitError(new Error(`Weft SSE: max reconnect attempts reached`));
|
|
591
597
|
return;
|
|
592
598
|
}
|
|
593
599
|
this.reconnectAttempts++;
|
|
@@ -624,8 +630,8 @@ function parseSseBuffer(buffer) {
|
|
|
624
630
|
}
|
|
625
631
|
return { items, remainder };
|
|
626
632
|
}
|
|
627
|
-
function
|
|
628
|
-
return new
|
|
633
|
+
function createTimelineStream(options) {
|
|
634
|
+
return new WeftFetchSseTimelineStream(options);
|
|
629
635
|
}
|
|
630
636
|
var TimelineSubscriptionImpl = class {
|
|
631
637
|
constructor(stream) {
|
|
@@ -689,7 +695,7 @@ var WeftClient = class {
|
|
|
689
695
|
options;
|
|
690
696
|
constructor(options) {
|
|
691
697
|
this.options = options;
|
|
692
|
-
this.http = new
|
|
698
|
+
this.http = new WeftHttpClient({
|
|
693
699
|
baseUrl: options.server,
|
|
694
700
|
apiKey: options.apiKey,
|
|
695
701
|
tenantId: options.tenantId,
|
|
@@ -727,7 +733,7 @@ var WeftClient = class {
|
|
|
727
733
|
* async iterable (`for await`).
|
|
728
734
|
*/
|
|
729
735
|
subscribe: (sessionId, options) => {
|
|
730
|
-
const stream = new
|
|
736
|
+
const stream = new WeftFetchSseTimelineStream({
|
|
731
737
|
url: this.http.sessionTimelineUrl(sessionId),
|
|
732
738
|
apiKey: this.options.apiKey,
|
|
733
739
|
tenantId: this.options.token ? void 0 : this.options.tenantId,
|
|
@@ -908,7 +914,7 @@ function createFlitroRuntimeCapabilityReport(options) {
|
|
|
908
914
|
function createFlitroProviderRuntime(options) {
|
|
909
915
|
const report = createFlitroRuntimeCapabilityReport(options);
|
|
910
916
|
const extensions = createRuntimeExtensionContext(options.extensions);
|
|
911
|
-
const client = new
|
|
917
|
+
const client = new WeftHttpClient(options.server);
|
|
912
918
|
let resolvedSessionId = options.sessionId ?? "";
|
|
913
919
|
let epoch = options.epoch ?? (resolvedSessionId ? `flitro-${resolvedSessionId}` : "flitro-pending");
|
|
914
920
|
const now = options.now ?? (() => Date.now());
|
|
@@ -1029,7 +1035,7 @@ function createFlitroProviderRuntime(options) {
|
|
|
1029
1035
|
}
|
|
1030
1036
|
function connectSse() {
|
|
1031
1037
|
if (!resolvedSessionId || sseStream) return;
|
|
1032
|
-
sseStream =
|
|
1038
|
+
sseStream = createTimelineStream({
|
|
1033
1039
|
url: client.sessionTimelineUrl(resolvedSessionId),
|
|
1034
1040
|
apiKey: options.server.apiKey,
|
|
1035
1041
|
tenantId: options.server.tenantId,
|
|
@@ -1173,7 +1179,7 @@ var PushTimelineStream = class {
|
|
|
1173
1179
|
}
|
|
1174
1180
|
};
|
|
1175
1181
|
async function createFlitroRuntime(options) {
|
|
1176
|
-
const client = new
|
|
1182
|
+
const client = new WeftHttpClient(options.server);
|
|
1177
1183
|
const probe = await probeFlitroCapabilities(client);
|
|
1178
1184
|
return createFlitroProviderRuntime({
|
|
1179
1185
|
server: options.server,
|
|
@@ -1191,16 +1197,16 @@ async function createFlitroRuntime(options) {
|
|
|
1191
1197
|
});
|
|
1192
1198
|
}
|
|
1193
1199
|
export {
|
|
1194
|
-
FlitroFetchSseTimelineStream,
|
|
1195
|
-
FlitroHttpClient,
|
|
1196
|
-
FlitroSseTimelineStream,
|
|
1197
1200
|
WeftClient,
|
|
1201
|
+
WeftFetchSseTimelineStream,
|
|
1202
|
+
WeftHttpClient,
|
|
1203
|
+
WeftSseTimelineStream,
|
|
1198
1204
|
createFlitroDriver,
|
|
1199
1205
|
createFlitroEmbedRuntime,
|
|
1200
1206
|
createFlitroProviderRuntime,
|
|
1201
1207
|
createFlitroRuntime,
|
|
1202
1208
|
createFlitroRuntimeCandidates,
|
|
1203
1209
|
createFlitroRuntimeCapabilityReport,
|
|
1204
|
-
|
|
1210
|
+
createTimelineStream,
|
|
1205
1211
|
probeFlitroCapabilities
|
|
1206
1212
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percena/weft",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.9",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "Weft — Agentic Chat SDK for Percena. Single install for streaming chat UI,
|
|
5
|
+
"description": "Weft — Agentic Chat SDK for Percena. Single install for streaming chat UI, embed runtime, action replay, and browser skills. Server-side functionality is handled by weftd (Go).",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
8
|
"module": "./dist/index.js",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@types/node": "^22.0.0",
|
|
92
92
|
"@types/react": "^19.2.14",
|
|
93
93
|
"@weft/core": "workspace:*",
|
|
94
|
-
"@weft/
|
|
94
|
+
"@weft/chat": "workspace:*",
|
|
95
95
|
"@weft/provider-flitro": "workspace:*",
|
|
96
96
|
"@weft/runtime-core": "workspace:*",
|
|
97
97
|
"@weft/timeline": "workspace:*",
|