@truefoundry/assistant-ui-runtime 0.1.2 → 0.1.3-rc.1
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/index.d.ts +21 -8
- package/dist/index.js +104 -1057
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/draftAgentConfig.test.ts +30 -1
- package/src/index.ts +3 -0
- package/src/loadSessionSnapshot.ts +1 -1
- package/src/private/bindDraftAgentSession.test.ts +17 -19
- package/src/private/bindDraftAgentSession.ts +14 -52
- package/src/private/draftSessionBridge.ts +6 -8
- package/src/private/getGatewayFromPrivateClient.ts +13 -0
- package/src/private/truefoundryDraftThreadListAdapter.test.ts +41 -31
- package/src/private/truefoundryDraftThreadListAdapter.ts +8 -8
- package/src/sessions.ts +5 -5
- package/src/truefoundryOwnedSessionsThreadListAdapter.test.ts +100 -0
- package/src/truefoundryOwnedSessionsThreadListAdapter.ts +77 -0
- package/src/types.ts +10 -7
- package/src/useTrueFoundryAgentMessages.test.tsx +5 -5
- package/src/useTrueFoundryAgentMessages.ts +6 -6
- package/src/useTrueFoundryAgentRuntime.ts +15 -12
- package/src/agentSessionModule.d.ts +0 -37
package/dist/index.js
CHANGED
|
@@ -2326,19 +2326,25 @@ function repositoryItemsFromMessages(messages) {
|
|
|
2326
2326
|
return items;
|
|
2327
2327
|
}
|
|
2328
2328
|
|
|
2329
|
+
// src/private/getGatewayFromPrivateClient.ts
|
|
2330
|
+
function getGatewayFromPrivateClient(privateClient) {
|
|
2331
|
+
const internal = privateClient;
|
|
2332
|
+
if (internal.client == null) {
|
|
2333
|
+
throw new Error("PrivateAgentSessionClient is missing an internal gateway client.");
|
|
2334
|
+
}
|
|
2335
|
+
return internal.client;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2329
2338
|
// src/private/draftSessionBridge.ts
|
|
2330
2339
|
var DRAFT_SESSION_LAST_UPDATED_AT_HEADER = "x-tfy-session-last-updated-at";
|
|
2331
|
-
function createDraftSessionBridge(
|
|
2332
|
-
async function getDraft(draftSessionId) {
|
|
2333
|
-
const response = await gateway.agents.private.draftSessions.get(draftSessionId);
|
|
2334
|
-
return response.data;
|
|
2335
|
-
}
|
|
2340
|
+
function createDraftSessionBridge(privateClient) {
|
|
2336
2341
|
return {
|
|
2337
2342
|
async getDraftAgentSpec(draftSessionId) {
|
|
2338
|
-
const draft = await
|
|
2343
|
+
const draft = await privateClient.getDraftSession({ draftSessionId });
|
|
2339
2344
|
return draft.agentSpec;
|
|
2340
2345
|
},
|
|
2341
2346
|
async syncAgentSpec(draftSessionId, agentSpec) {
|
|
2347
|
+
const gateway = getGatewayFromPrivateClient(privateClient);
|
|
2342
2348
|
const response = await gateway.agents.private.draftSessions.update(
|
|
2343
2349
|
draftSessionId,
|
|
2344
2350
|
{ agentSpec }
|
|
@@ -2379,10 +2385,10 @@ function sessionListStartTimestamp() {
|
|
|
2379
2385
|
// src/private/truefoundryDraftThreadListAdapter.ts
|
|
2380
2386
|
var THREAD_LIST_PAGE_SIZE = 20;
|
|
2381
2387
|
function createTrueFoundryDraftThreadListAdapter(options) {
|
|
2382
|
-
const {
|
|
2388
|
+
const { privateClient, defaultAgentSpec, getAgentSpec } = options;
|
|
2383
2389
|
return {
|
|
2384
2390
|
async list({ after } = {}) {
|
|
2385
|
-
const page = await
|
|
2391
|
+
const page = await privateClient.listDraftSessions({
|
|
2386
2392
|
limit: THREAD_LIST_PAGE_SIZE,
|
|
2387
2393
|
pageToken: after,
|
|
2388
2394
|
startTimestamp: sessionListStartTimestamp()
|
|
@@ -2399,15 +2405,15 @@ function createTrueFoundryDraftThreadListAdapter(options) {
|
|
|
2399
2405
|
};
|
|
2400
2406
|
},
|
|
2401
2407
|
async initialize(_threadId) {
|
|
2402
|
-
const
|
|
2408
|
+
const draft = await privateClient.createDraftSession({
|
|
2403
2409
|
agentSpec: getAgentSpec?.() ?? defaultAgentSpec
|
|
2404
2410
|
});
|
|
2405
|
-
const draft = response.data;
|
|
2406
2411
|
return { remoteId: draft.id, externalId: void 0 };
|
|
2407
2412
|
},
|
|
2408
2413
|
async fetch(remoteId) {
|
|
2409
|
-
const
|
|
2410
|
-
|
|
2414
|
+
const draft = await privateClient.getDraftSession({
|
|
2415
|
+
draftSessionId: remoteId
|
|
2416
|
+
});
|
|
2411
2417
|
return {
|
|
2412
2418
|
status: "regular",
|
|
2413
2419
|
remoteId: draft.id,
|
|
@@ -2444,1035 +2450,12 @@ var EMPTY_DRAFT_EXTRAS = {
|
|
|
2444
2450
|
}
|
|
2445
2451
|
};
|
|
2446
2452
|
|
|
2447
|
-
// ../../node_modules/.pnpm/truefoundry-gateway-sdk@0.3.1/node_modules/truefoundry-gateway-sdk/dist/esm/core/fetcher/HttpResponsePromise.mjs
|
|
2448
|
-
var __awaiter = function(thisArg, _arguments, P, generator) {
|
|
2449
|
-
function adopt(value) {
|
|
2450
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
2451
|
-
resolve(value);
|
|
2452
|
-
});
|
|
2453
|
-
}
|
|
2454
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2455
|
-
function fulfilled(value) {
|
|
2456
|
-
try {
|
|
2457
|
-
step(generator.next(value));
|
|
2458
|
-
} catch (e) {
|
|
2459
|
-
reject(e);
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
function rejected(value) {
|
|
2463
|
-
try {
|
|
2464
|
-
step(generator["throw"](value));
|
|
2465
|
-
} catch (e) {
|
|
2466
|
-
reject(e);
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
function step(result) {
|
|
2470
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2471
|
-
}
|
|
2472
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2473
|
-
});
|
|
2474
|
-
};
|
|
2475
|
-
var HttpResponsePromise = class _HttpResponsePromise extends Promise {
|
|
2476
|
-
constructor(promise) {
|
|
2477
|
-
super((resolve) => {
|
|
2478
|
-
resolve(void 0);
|
|
2479
|
-
});
|
|
2480
|
-
this.innerPromise = promise;
|
|
2481
|
-
}
|
|
2482
|
-
/**
|
|
2483
|
-
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
2484
|
-
*
|
|
2485
|
-
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
2486
|
-
* @param args - Arguments to pass to the function.
|
|
2487
|
-
* @returns An `HttpResponsePromise` instance.
|
|
2488
|
-
*/
|
|
2489
|
-
static fromFunction(fn, ...args) {
|
|
2490
|
-
return new _HttpResponsePromise(fn(...args));
|
|
2491
|
-
}
|
|
2492
|
-
/**
|
|
2493
|
-
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
2494
|
-
*
|
|
2495
|
-
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
2496
|
-
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
2497
|
-
*/
|
|
2498
|
-
static interceptFunction(fn) {
|
|
2499
|
-
return (...args) => {
|
|
2500
|
-
return _HttpResponsePromise.fromPromise(fn(...args));
|
|
2501
|
-
};
|
|
2502
|
-
}
|
|
2503
|
-
/**
|
|
2504
|
-
* Creates an `HttpResponsePromise` from an existing promise.
|
|
2505
|
-
*
|
|
2506
|
-
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
2507
|
-
* @returns An `HttpResponsePromise` instance.
|
|
2508
|
-
*/
|
|
2509
|
-
static fromPromise(promise) {
|
|
2510
|
-
return new _HttpResponsePromise(promise);
|
|
2511
|
-
}
|
|
2512
|
-
/**
|
|
2513
|
-
* Creates an `HttpResponsePromise` from an executor function.
|
|
2514
|
-
*
|
|
2515
|
-
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
2516
|
-
* @returns An `HttpResponsePromise` instance.
|
|
2517
|
-
*/
|
|
2518
|
-
static fromExecutor(executor) {
|
|
2519
|
-
const promise = new Promise(executor);
|
|
2520
|
-
return new _HttpResponsePromise(promise);
|
|
2521
|
-
}
|
|
2522
|
-
/**
|
|
2523
|
-
* Creates an `HttpResponsePromise` from a resolved result.
|
|
2524
|
-
*
|
|
2525
|
-
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
2526
|
-
* @returns An `HttpResponsePromise` instance.
|
|
2527
|
-
*/
|
|
2528
|
-
static fromResult(result) {
|
|
2529
|
-
const promise = Promise.resolve(result);
|
|
2530
|
-
return new _HttpResponsePromise(promise);
|
|
2531
|
-
}
|
|
2532
|
-
unwrap() {
|
|
2533
|
-
if (!this.unwrappedPromise) {
|
|
2534
|
-
this.unwrappedPromise = this.innerPromise.then(({ data }) => data);
|
|
2535
|
-
}
|
|
2536
|
-
return this.unwrappedPromise;
|
|
2537
|
-
}
|
|
2538
|
-
/** @inheritdoc */
|
|
2539
|
-
then(onfulfilled, onrejected) {
|
|
2540
|
-
return this.unwrap().then(onfulfilled, onrejected);
|
|
2541
|
-
}
|
|
2542
|
-
/** @inheritdoc */
|
|
2543
|
-
catch(onrejected) {
|
|
2544
|
-
return this.unwrap().catch(onrejected);
|
|
2545
|
-
}
|
|
2546
|
-
/** @inheritdoc */
|
|
2547
|
-
finally(onfinally) {
|
|
2548
|
-
return this.unwrap().finally(onfinally);
|
|
2549
|
-
}
|
|
2550
|
-
/**
|
|
2551
|
-
* Retrieves the data and raw response.
|
|
2552
|
-
*
|
|
2553
|
-
* @returns A promise resolving to a `WithRawResponse` object.
|
|
2554
|
-
*/
|
|
2555
|
-
withRawResponse() {
|
|
2556
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2557
|
-
return yield this.innerPromise;
|
|
2558
|
-
});
|
|
2559
|
-
}
|
|
2560
|
-
};
|
|
2561
|
-
|
|
2562
|
-
// ../../node_modules/.pnpm/truefoundry-gateway-sdk@0.3.1/node_modules/truefoundry-gateway-sdk/dist/esm/core/pagination/Page.mjs
|
|
2563
|
-
var __awaiter2 = function(thisArg, _arguments, P, generator) {
|
|
2564
|
-
function adopt(value) {
|
|
2565
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
2566
|
-
resolve(value);
|
|
2567
|
-
});
|
|
2568
|
-
}
|
|
2569
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2570
|
-
function fulfilled(value) {
|
|
2571
|
-
try {
|
|
2572
|
-
step(generator.next(value));
|
|
2573
|
-
} catch (e) {
|
|
2574
|
-
reject(e);
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
function rejected(value) {
|
|
2578
|
-
try {
|
|
2579
|
-
step(generator["throw"](value));
|
|
2580
|
-
} catch (e) {
|
|
2581
|
-
reject(e);
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
function step(result) {
|
|
2585
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2586
|
-
}
|
|
2587
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2588
|
-
});
|
|
2589
|
-
};
|
|
2590
|
-
var __await = function(v) {
|
|
2591
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
2592
|
-
};
|
|
2593
|
-
var __asyncGenerator = function(thisArg, _arguments, generator) {
|
|
2594
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
2595
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
2596
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
|
|
2597
|
-
return this;
|
|
2598
|
-
}, i;
|
|
2599
|
-
function awaitReturn(f) {
|
|
2600
|
-
return function(v) {
|
|
2601
|
-
return Promise.resolve(v).then(f, reject);
|
|
2602
|
-
};
|
|
2603
|
-
}
|
|
2604
|
-
function verb(n, f) {
|
|
2605
|
-
if (g[n]) {
|
|
2606
|
-
i[n] = function(v) {
|
|
2607
|
-
return new Promise(function(a, b) {
|
|
2608
|
-
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
2609
|
-
});
|
|
2610
|
-
};
|
|
2611
|
-
if (f) i[n] = f(i[n]);
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
function resume(n, v) {
|
|
2615
|
-
try {
|
|
2616
|
-
step(g[n](v));
|
|
2617
|
-
} catch (e) {
|
|
2618
|
-
settle(q[0][3], e);
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
function step(r) {
|
|
2622
|
-
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
2623
|
-
}
|
|
2624
|
-
function fulfill(value) {
|
|
2625
|
-
resume("next", value);
|
|
2626
|
-
}
|
|
2627
|
-
function reject(value) {
|
|
2628
|
-
resume("throw", value);
|
|
2629
|
-
}
|
|
2630
|
-
function settle(f, v) {
|
|
2631
|
-
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
|
|
2632
|
-
}
|
|
2633
|
-
};
|
|
2634
|
-
var __asyncValues = function(o) {
|
|
2635
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
2636
|
-
var m = o[Symbol.asyncIterator], i;
|
|
2637
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
2638
|
-
return this;
|
|
2639
|
-
}, i);
|
|
2640
|
-
function verb(n) {
|
|
2641
|
-
i[n] = o[n] && function(v) {
|
|
2642
|
-
return new Promise(function(resolve, reject) {
|
|
2643
|
-
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
2644
|
-
});
|
|
2645
|
-
};
|
|
2646
|
-
}
|
|
2647
|
-
function settle(resolve, reject, d, v) {
|
|
2648
|
-
Promise.resolve(v).then(function(v2) {
|
|
2649
|
-
resolve({ value: v2, done: d });
|
|
2650
|
-
}, reject);
|
|
2651
|
-
}
|
|
2652
|
-
};
|
|
2653
|
-
var Page = class {
|
|
2654
|
-
constructor({ response, rawResponse, hasNextPage, getItems, loadPage }) {
|
|
2655
|
-
this.response = response;
|
|
2656
|
-
this.rawResponse = rawResponse;
|
|
2657
|
-
this.data = getItems(response);
|
|
2658
|
-
this._hasNextPage = hasNextPage;
|
|
2659
|
-
this.getItems = getItems;
|
|
2660
|
-
this.loadNextPage = loadPage;
|
|
2661
|
-
}
|
|
2662
|
-
/**
|
|
2663
|
-
* Retrieves the next page
|
|
2664
|
-
* @returns this
|
|
2665
|
-
*/
|
|
2666
|
-
getNextPage() {
|
|
2667
|
-
return __awaiter2(this, void 0, void 0, function* () {
|
|
2668
|
-
const { data, rawResponse } = yield this.loadNextPage(this.response).withRawResponse();
|
|
2669
|
-
this.response = data;
|
|
2670
|
-
this.rawResponse = rawResponse;
|
|
2671
|
-
this.data = this.getItems(this.response);
|
|
2672
|
-
return this;
|
|
2673
|
-
});
|
|
2674
|
-
}
|
|
2675
|
-
/**
|
|
2676
|
-
* @returns whether there is a next page to load
|
|
2677
|
-
*/
|
|
2678
|
-
hasNextPage() {
|
|
2679
|
-
return this._hasNextPage(this.response);
|
|
2680
|
-
}
|
|
2681
|
-
iterMessages() {
|
|
2682
|
-
return __asyncGenerator(this, arguments, function* iterMessages_1() {
|
|
2683
|
-
for (const item of this.data) {
|
|
2684
|
-
yield yield __await(item);
|
|
2685
|
-
}
|
|
2686
|
-
while (this.hasNextPage()) {
|
|
2687
|
-
yield __await(this.getNextPage());
|
|
2688
|
-
for (const item of this.data) {
|
|
2689
|
-
yield yield __await(item);
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
});
|
|
2693
|
-
}
|
|
2694
|
-
[Symbol.asyncIterator]() {
|
|
2695
|
-
return __asyncGenerator(this, arguments, function* _a() {
|
|
2696
|
-
var _b, e_1, _c, _d;
|
|
2697
|
-
try {
|
|
2698
|
-
for (var _e = true, _f = __asyncValues(this.iterMessages()), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
|
|
2699
|
-
_d = _g.value;
|
|
2700
|
-
_e = false;
|
|
2701
|
-
const message = _d;
|
|
2702
|
-
yield yield __await(message);
|
|
2703
|
-
}
|
|
2704
|
-
} catch (e_1_1) {
|
|
2705
|
-
e_1 = { error: e_1_1 };
|
|
2706
|
-
} finally {
|
|
2707
|
-
try {
|
|
2708
|
-
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
|
|
2709
|
-
} finally {
|
|
2710
|
-
if (e_1) throw e_1.error;
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
});
|
|
2714
|
-
}
|
|
2715
|
-
};
|
|
2716
|
-
|
|
2717
|
-
// ../../node_modules/.pnpm/truefoundry-gateway-sdk@0.3.1/node_modules/truefoundry-gateway-sdk/dist/esm/agents/TurnStreamData.mjs
|
|
2718
|
-
function parseSequenceNumber(id) {
|
|
2719
|
-
if (!id) {
|
|
2720
|
-
throw new Error("Missing SSE sequence number id.");
|
|
2721
|
-
}
|
|
2722
|
-
const parsed = Number(id);
|
|
2723
|
-
if (!Number.isFinite(parsed)) {
|
|
2724
|
-
throw new Error(`Invalid SSE sequence number id: "${id}".`);
|
|
2725
|
-
}
|
|
2726
|
-
return parsed;
|
|
2727
|
-
}
|
|
2728
|
-
|
|
2729
|
-
// ../../node_modules/.pnpm/truefoundry-gateway-sdk@0.3.1/node_modules/truefoundry-gateway-sdk/dist/esm/agents/Turn.mjs
|
|
2730
|
-
var __awaiter3 = function(thisArg, _arguments, P, generator) {
|
|
2731
|
-
function adopt(value) {
|
|
2732
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
2733
|
-
resolve(value);
|
|
2734
|
-
});
|
|
2735
|
-
}
|
|
2736
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2737
|
-
function fulfilled(value) {
|
|
2738
|
-
try {
|
|
2739
|
-
step(generator.next(value));
|
|
2740
|
-
} catch (e) {
|
|
2741
|
-
reject(e);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
function rejected(value) {
|
|
2745
|
-
try {
|
|
2746
|
-
step(generator["throw"](value));
|
|
2747
|
-
} catch (e) {
|
|
2748
|
-
reject(e);
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
function step(result) {
|
|
2752
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2753
|
-
}
|
|
2754
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2755
|
-
});
|
|
2756
|
-
};
|
|
2757
|
-
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
2758
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2759
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2760
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
2761
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
2762
|
-
};
|
|
2763
|
-
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
2764
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
2765
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
2766
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2767
|
-
};
|
|
2768
|
-
var __await2 = function(v) {
|
|
2769
|
-
return this instanceof __await2 ? (this.v = v, this) : new __await2(v);
|
|
2770
|
-
};
|
|
2771
|
-
var __asyncValues2 = function(o) {
|
|
2772
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
2773
|
-
var m = o[Symbol.asyncIterator], i;
|
|
2774
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
2775
|
-
return this;
|
|
2776
|
-
}, i);
|
|
2777
|
-
function verb(n) {
|
|
2778
|
-
i[n] = o[n] && function(v) {
|
|
2779
|
-
return new Promise(function(resolve, reject) {
|
|
2780
|
-
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
2781
|
-
});
|
|
2782
|
-
};
|
|
2783
|
-
}
|
|
2784
|
-
function settle(resolve, reject, d, v) {
|
|
2785
|
-
Promise.resolve(v).then(function(v2) {
|
|
2786
|
-
resolve({ value: v2, done: d });
|
|
2787
|
-
}, reject);
|
|
2788
|
-
}
|
|
2789
|
-
};
|
|
2790
|
-
var __asyncGenerator2 = function(thisArg, _arguments, generator) {
|
|
2791
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
2792
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
2793
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
|
|
2794
|
-
return this;
|
|
2795
|
-
}, i;
|
|
2796
|
-
function awaitReturn(f) {
|
|
2797
|
-
return function(v) {
|
|
2798
|
-
return Promise.resolve(v).then(f, reject);
|
|
2799
|
-
};
|
|
2800
|
-
}
|
|
2801
|
-
function verb(n, f) {
|
|
2802
|
-
if (g[n]) {
|
|
2803
|
-
i[n] = function(v) {
|
|
2804
|
-
return new Promise(function(a, b) {
|
|
2805
|
-
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
2806
|
-
});
|
|
2807
|
-
};
|
|
2808
|
-
if (f) i[n] = f(i[n]);
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
function resume(n, v) {
|
|
2812
|
-
try {
|
|
2813
|
-
step(g[n](v));
|
|
2814
|
-
} catch (e) {
|
|
2815
|
-
settle(q[0][3], e);
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
function step(r) {
|
|
2819
|
-
r.value instanceof __await2 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
2820
|
-
}
|
|
2821
|
-
function fulfill(value) {
|
|
2822
|
-
resume("next", value);
|
|
2823
|
-
}
|
|
2824
|
-
function reject(value) {
|
|
2825
|
-
resume("throw", value);
|
|
2826
|
-
}
|
|
2827
|
-
function settle(f, v) {
|
|
2828
|
-
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
|
|
2829
|
-
}
|
|
2830
|
-
};
|
|
2831
|
-
var _Turn_instances;
|
|
2832
|
-
var _Turn_client;
|
|
2833
|
-
var _Turn_state;
|
|
2834
|
-
var _Turn_applyEvent;
|
|
2835
|
-
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
2836
|
-
var MIN_POLL_INTERVAL_MS = 3e3;
|
|
2837
|
-
var Turn = class {
|
|
2838
|
-
constructor(turn, session, client) {
|
|
2839
|
-
_Turn_instances.add(this);
|
|
2840
|
-
_Turn_client.set(this, void 0);
|
|
2841
|
-
_Turn_state.set(this, void 0);
|
|
2842
|
-
this.id = turn.id;
|
|
2843
|
-
this.sessionId = turn.sessionId;
|
|
2844
|
-
this.previousTurnId = turn.previousTurnId;
|
|
2845
|
-
this.input = turn.input;
|
|
2846
|
-
this.createdBySubject = turn.createdBySubject;
|
|
2847
|
-
this.createdAt = turn.createdAt;
|
|
2848
|
-
__classPrivateFieldSet(this, _Turn_state, turn.state, "f");
|
|
2849
|
-
this.session = session;
|
|
2850
|
-
__classPrivateFieldSet(this, _Turn_client, client, "f");
|
|
2851
|
-
}
|
|
2852
|
-
/**
|
|
2853
|
-
* @returns {TrueFoundryGatewayApi.TurnState} Updated by `refresh()`, `stream()`, and `waitForCompletion()`.
|
|
2854
|
-
*/
|
|
2855
|
-
get state() {
|
|
2856
|
-
return __classPrivateFieldGet(this, _Turn_state, "f");
|
|
2857
|
-
}
|
|
2858
|
-
// Terminal states are listed explicitly (not `status !== "running"`) so a newly added
|
|
2859
|
-
// non-terminal status keeps polling by default; new terminal states must be added here.
|
|
2860
|
-
isTerminal(state) {
|
|
2861
|
-
switch (state.status) {
|
|
2862
|
-
case "done":
|
|
2863
|
-
case "cancelled":
|
|
2864
|
-
case "error":
|
|
2865
|
-
return true;
|
|
2866
|
-
default:
|
|
2867
|
-
return false;
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
// Refetch from the server, update #state in place, and return self.
|
|
2871
|
-
/**
|
|
2872
|
-
* Refetch from the server, update state in-place and return self.
|
|
2873
|
-
*
|
|
2874
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
2875
|
-
* @returns {this} This turn with updated state.
|
|
2876
|
-
*/
|
|
2877
|
-
refresh(requestOptions) {
|
|
2878
|
-
return __awaiter3(this, void 0, void 0, function* () {
|
|
2879
|
-
const response = yield __classPrivateFieldGet(this, _Turn_client, "f").agents.sessions.getTurn(this.sessionId, this.id, requestOptions);
|
|
2880
|
-
__classPrivateFieldSet(this, _Turn_state, response.data.state, "f");
|
|
2881
|
-
return this;
|
|
2882
|
-
});
|
|
2883
|
-
}
|
|
2884
|
-
/**
|
|
2885
|
-
* Poll getTurn until terminal.
|
|
2886
|
-
*
|
|
2887
|
-
* @param opts.pollIntervalMs - Poll interval ms while waiting. Minimum 3000.
|
|
2888
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
2889
|
-
* @returns {TrueFoundryGatewayApi.TurnState} Terminal turn state.
|
|
2890
|
-
*/
|
|
2891
|
-
waitForCompletion(opts, requestOptions) {
|
|
2892
|
-
return __awaiter3(this, void 0, void 0, function* () {
|
|
2893
|
-
var _a;
|
|
2894
|
-
const pollIntervalMs = (_a = opts === null || opts === void 0 ? void 0 : opts.pollIntervalMs) !== null && _a !== void 0 ? _a : DEFAULT_POLL_INTERVAL_MS;
|
|
2895
|
-
if (pollIntervalMs < MIN_POLL_INTERVAL_MS) {
|
|
2896
|
-
throw new Error(`pollIntervalMs must be at least ${MIN_POLL_INTERVAL_MS}ms`);
|
|
2897
|
-
}
|
|
2898
|
-
while (!this.isTerminal(__classPrivateFieldGet(this, _Turn_state, "f"))) {
|
|
2899
|
-
yield new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
2900
|
-
yield this.refresh(requestOptions);
|
|
2901
|
-
}
|
|
2902
|
-
return __classPrivateFieldGet(this, _Turn_state, "f");
|
|
2903
|
-
});
|
|
2904
|
-
}
|
|
2905
|
-
// Reconnect to the turn's SSE; let the server decide what to stream (no client-side guard).
|
|
2906
|
-
// Updates #state in place from any event that carries a state snapshot.
|
|
2907
|
-
/**
|
|
2908
|
-
* Reconnect to the turn's SSE. Updates state in-place from lifecycle events.
|
|
2909
|
-
*
|
|
2910
|
-
* @param opts.afterSequenceNumber - Sequence number to resume SSE subscription after.
|
|
2911
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
2912
|
-
* @yields {TurnStreamData} SSE stream items.
|
|
2913
|
-
*/
|
|
2914
|
-
stream(opts, requestOptions) {
|
|
2915
|
-
return __asyncGenerator2(this, arguments, function* stream_1() {
|
|
2916
|
-
var _a, e_1, _b, _c;
|
|
2917
|
-
const sse = yield __await2(__classPrivateFieldGet(this, _Turn_client, "f").agents.sessions.subscribeToTurn(this.sessionId, this.id, { afterSequenceNumber: opts === null || opts === void 0 ? void 0 : opts.afterSequenceNumber }, requestOptions));
|
|
2918
|
-
try {
|
|
2919
|
-
for (var _d = true, _e = __asyncValues2(sse.withMetadata()), _f; _f = yield __await2(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
2920
|
-
_c = _f.value;
|
|
2921
|
-
_d = false;
|
|
2922
|
-
const { data: event, id } = _c;
|
|
2923
|
-
__classPrivateFieldGet(this, _Turn_instances, "m", _Turn_applyEvent).call(this, event);
|
|
2924
|
-
yield yield __await2({ sequenceNumber: parseSequenceNumber(id), event });
|
|
2925
|
-
}
|
|
2926
|
-
} catch (e_1_1) {
|
|
2927
|
-
e_1 = { error: e_1_1 };
|
|
2928
|
-
} finally {
|
|
2929
|
-
try {
|
|
2930
|
-
if (!_d && !_a && (_b = _e.return)) yield __await2(_b.call(_e));
|
|
2931
|
-
} finally {
|
|
2932
|
-
if (e_1) throw e_1.error;
|
|
2933
|
-
}
|
|
2934
|
-
}
|
|
2935
|
-
});
|
|
2936
|
-
}
|
|
2937
|
-
/**
|
|
2938
|
-
* Cancel the running last turn for the session.
|
|
2939
|
-
*
|
|
2940
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
2941
|
-
* @returns {void}
|
|
2942
|
-
*/
|
|
2943
|
-
cancel(requestOptions) {
|
|
2944
|
-
return __awaiter3(this, void 0, void 0, function* () {
|
|
2945
|
-
yield __classPrivateFieldGet(this, _Turn_client, "f").agents.sessions.cancel(this.sessionId, {}, requestOptions);
|
|
2946
|
-
});
|
|
2947
|
-
}
|
|
2948
|
-
// Expose the autogen Fern Page as-is (it is already async-iterable); no re-wrapping.
|
|
2949
|
-
/**
|
|
2950
|
-
* Paginated turn events; use `stream()` for live SSE.
|
|
2951
|
-
*
|
|
2952
|
-
* @param opts.pageToken - Token from the previous response nextPageToken.
|
|
2953
|
-
* @param opts.limit - Page size. Default 25.
|
|
2954
|
-
* @param opts.order - Sort by creation time. Default `asc`.
|
|
2955
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
2956
|
-
* @returns {Promise<core.Page<TrueFoundryGatewayApi.TurnEvent, TrueFoundryGatewayApi.ListEventsResponse>>} Paginated turn events.
|
|
2957
|
-
*/
|
|
2958
|
-
listEvents(opts, requestOptions) {
|
|
2959
|
-
return __classPrivateFieldGet(this, _Turn_client, "f").agents.sessions.listTurnEvents(this.sessionId, this.id, opts, requestOptions);
|
|
2960
|
-
}
|
|
2961
|
-
};
|
|
2962
|
-
_Turn_client = /* @__PURE__ */ new WeakMap(), _Turn_state = /* @__PURE__ */ new WeakMap(), _Turn_instances = /* @__PURE__ */ new WeakSet(), _Turn_applyEvent = function _Turn_applyEvent2(event) {
|
|
2963
|
-
if (event.type === "turn.created" || event.type === "turn.done")
|
|
2964
|
-
__classPrivateFieldSet(this, _Turn_state, event.state, "f");
|
|
2965
|
-
};
|
|
2966
|
-
|
|
2967
|
-
// ../../node_modules/.pnpm/truefoundry-gateway-sdk@0.3.1/node_modules/truefoundry-gateway-sdk/dist/esm/agents/PreparedTurn.mjs
|
|
2968
|
-
var __awaiter4 = function(thisArg, _arguments, P, generator) {
|
|
2969
|
-
function adopt(value) {
|
|
2970
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
2971
|
-
resolve(value);
|
|
2972
|
-
});
|
|
2973
|
-
}
|
|
2974
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2975
|
-
function fulfilled(value) {
|
|
2976
|
-
try {
|
|
2977
|
-
step(generator.next(value));
|
|
2978
|
-
} catch (e) {
|
|
2979
|
-
reject(e);
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
function rejected(value) {
|
|
2983
|
-
try {
|
|
2984
|
-
step(generator["throw"](value));
|
|
2985
|
-
} catch (e) {
|
|
2986
|
-
reject(e);
|
|
2987
|
-
}
|
|
2988
|
-
}
|
|
2989
|
-
function step(result) {
|
|
2990
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2991
|
-
}
|
|
2992
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2993
|
-
});
|
|
2994
|
-
};
|
|
2995
|
-
var __classPrivateFieldSet2 = function(receiver, state, value, kind, f) {
|
|
2996
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2997
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2998
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
2999
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
3000
|
-
};
|
|
3001
|
-
var __classPrivateFieldGet2 = function(receiver, state, kind, f) {
|
|
3002
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3003
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
3004
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
3005
|
-
};
|
|
3006
|
-
var __asyncValues3 = function(o) {
|
|
3007
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3008
|
-
var m = o[Symbol.asyncIterator], i;
|
|
3009
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
3010
|
-
return this;
|
|
3011
|
-
}, i);
|
|
3012
|
-
function verb(n) {
|
|
3013
|
-
i[n] = o[n] && function(v) {
|
|
3014
|
-
return new Promise(function(resolve, reject) {
|
|
3015
|
-
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
3016
|
-
});
|
|
3017
|
-
};
|
|
3018
|
-
}
|
|
3019
|
-
function settle(resolve, reject, d, v) {
|
|
3020
|
-
Promise.resolve(v).then(function(v2) {
|
|
3021
|
-
resolve({ value: v2, done: d });
|
|
3022
|
-
}, reject);
|
|
3023
|
-
}
|
|
3024
|
-
};
|
|
3025
|
-
var __await3 = function(v) {
|
|
3026
|
-
return this instanceof __await3 ? (this.v = v, this) : new __await3(v);
|
|
3027
|
-
};
|
|
3028
|
-
var __asyncDelegator = function(o) {
|
|
3029
|
-
var i, p;
|
|
3030
|
-
return i = {}, verb("next"), verb("throw", function(e) {
|
|
3031
|
-
throw e;
|
|
3032
|
-
}), verb("return"), i[Symbol.iterator] = function() {
|
|
3033
|
-
return this;
|
|
3034
|
-
}, i;
|
|
3035
|
-
function verb(n, f) {
|
|
3036
|
-
i[n] = o[n] ? function(v) {
|
|
3037
|
-
return (p = !p) ? { value: __await3(o[n](v)), done: false } : f ? f(v) : v;
|
|
3038
|
-
} : f;
|
|
3039
|
-
}
|
|
3040
|
-
};
|
|
3041
|
-
var __asyncGenerator3 = function(thisArg, _arguments, generator) {
|
|
3042
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3043
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
3044
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
|
|
3045
|
-
return this;
|
|
3046
|
-
}, i;
|
|
3047
|
-
function awaitReturn(f) {
|
|
3048
|
-
return function(v) {
|
|
3049
|
-
return Promise.resolve(v).then(f, reject);
|
|
3050
|
-
};
|
|
3051
|
-
}
|
|
3052
|
-
function verb(n, f) {
|
|
3053
|
-
if (g[n]) {
|
|
3054
|
-
i[n] = function(v) {
|
|
3055
|
-
return new Promise(function(a, b) {
|
|
3056
|
-
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
3057
|
-
});
|
|
3058
|
-
};
|
|
3059
|
-
if (f) i[n] = f(i[n]);
|
|
3060
|
-
}
|
|
3061
|
-
}
|
|
3062
|
-
function resume(n, v) {
|
|
3063
|
-
try {
|
|
3064
|
-
step(g[n](v));
|
|
3065
|
-
} catch (e) {
|
|
3066
|
-
settle(q[0][3], e);
|
|
3067
|
-
}
|
|
3068
|
-
}
|
|
3069
|
-
function step(r) {
|
|
3070
|
-
r.value instanceof __await3 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
3071
|
-
}
|
|
3072
|
-
function fulfill(value) {
|
|
3073
|
-
resume("next", value);
|
|
3074
|
-
}
|
|
3075
|
-
function reject(value) {
|
|
3076
|
-
resume("throw", value);
|
|
3077
|
-
}
|
|
3078
|
-
function settle(f, v) {
|
|
3079
|
-
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
|
|
3080
|
-
}
|
|
3081
|
-
};
|
|
3082
|
-
var _PreparedTurn_client;
|
|
3083
|
-
var _PreparedTurn_input;
|
|
3084
|
-
var _PreparedTurn_previousTurnIdInput;
|
|
3085
|
-
var _PreparedTurn_start;
|
|
3086
|
-
var _PreparedTurn_turn;
|
|
3087
|
-
var PreparedTurn = class {
|
|
3088
|
-
constructor(init, session, client) {
|
|
3089
|
-
_PreparedTurn_client.set(this, void 0);
|
|
3090
|
-
_PreparedTurn_input.set(this, void 0);
|
|
3091
|
-
_PreparedTurn_previousTurnIdInput.set(this, void 0);
|
|
3092
|
-
_PreparedTurn_start.set(this, void 0);
|
|
3093
|
-
_PreparedTurn_turn.set(this, void 0);
|
|
3094
|
-
this.session = session;
|
|
3095
|
-
this.sessionId = session.id;
|
|
3096
|
-
__classPrivateFieldSet2(this, _PreparedTurn_client, client, "f");
|
|
3097
|
-
__classPrivateFieldSet2(this, _PreparedTurn_input, init.input, "f");
|
|
3098
|
-
__classPrivateFieldSet2(this, _PreparedTurn_previousTurnIdInput, init.previousTurnId, "f");
|
|
3099
|
-
}
|
|
3100
|
-
// Remaining data getters delegate to the inner Turn (undefined until started).
|
|
3101
|
-
/**
|
|
3102
|
-
* @returns {string | undefined} Undefined until `execute()` starts the turn.
|
|
3103
|
-
*/
|
|
3104
|
-
get id() {
|
|
3105
|
-
var _a;
|
|
3106
|
-
return (_a = __classPrivateFieldGet2(this, _PreparedTurn_turn, "f")) === null || _a === void 0 ? void 0 : _a.id;
|
|
3107
|
-
}
|
|
3108
|
-
/**
|
|
3109
|
-
* @returns {string | undefined} Undefined until `execute()` starts the turn.
|
|
3110
|
-
*/
|
|
3111
|
-
get previousTurnId() {
|
|
3112
|
-
var _a;
|
|
3113
|
-
return (_a = __classPrivateFieldGet2(this, _PreparedTurn_turn, "f")) === null || _a === void 0 ? void 0 : _a.previousTurnId;
|
|
3114
|
-
}
|
|
3115
|
-
/**
|
|
3116
|
-
* @returns {TrueFoundryGatewayApi.TurnState | undefined} Undefined until `execute()` starts the turn.
|
|
3117
|
-
*/
|
|
3118
|
-
get state() {
|
|
3119
|
-
var _a;
|
|
3120
|
-
return (_a = __classPrivateFieldGet2(this, _PreparedTurn_turn, "f")) === null || _a === void 0 ? void 0 : _a.state;
|
|
3121
|
-
}
|
|
3122
|
-
/**
|
|
3123
|
-
* @returns {TrueFoundryGatewayApi.Subject | undefined} Undefined until `execute()` starts the turn.
|
|
3124
|
-
*/
|
|
3125
|
-
get createdBySubject() {
|
|
3126
|
-
var _a;
|
|
3127
|
-
return (_a = __classPrivateFieldGet2(this, _PreparedTurn_turn, "f")) === null || _a === void 0 ? void 0 : _a.createdBySubject;
|
|
3128
|
-
}
|
|
3129
|
-
/**
|
|
3130
|
-
* @returns {string | undefined} Undefined until `execute()` starts the turn.
|
|
3131
|
-
*/
|
|
3132
|
-
get createdAt() {
|
|
3133
|
-
var _a;
|
|
3134
|
-
return (_a = __classPrivateFieldGet2(this, _PreparedTurn_turn, "f")) === null || _a === void 0 ? void 0 : _a.createdAt;
|
|
3135
|
-
}
|
|
3136
|
-
/**
|
|
3137
|
-
* @returns {TrueFoundryGatewayApi.TurnInputItem[] | undefined} Staged input before execute; inner turn input after.
|
|
3138
|
-
*/
|
|
3139
|
-
get input() {
|
|
3140
|
-
var _a, _b;
|
|
3141
|
-
return (_b = (_a = __classPrivateFieldGet2(this, _PreparedTurn_turn, "f")) === null || _a === void 0 ? void 0 : _a.input) !== null && _b !== void 0 ? _b : __classPrivateFieldGet2(this, _PreparedTurn_input, "f");
|
|
3142
|
-
}
|
|
3143
|
-
execute(opts, requestOptions) {
|
|
3144
|
-
if (__classPrivateFieldGet2(this, _PreparedTurn_start, "f") != null)
|
|
3145
|
-
throw new Error("Turn already started; use stream() / waitForCompletion().");
|
|
3146
|
-
__classPrivateFieldSet2(this, _PreparedTurn_start, this.openCreateTurn(requestOptions), "f");
|
|
3147
|
-
const { stream = true, pollIntervalMs } = opts !== null && opts !== void 0 ? opts : {};
|
|
3148
|
-
return stream === false ? this.startAndWait(pollIntervalMs, requestOptions) : this.runStreaming();
|
|
3149
|
-
}
|
|
3150
|
-
// Post-execution behaviors. Each throws via mustGetTurn() until execute() has started the turn,
|
|
3151
|
-
// then delegates to the inner Turn. stream() here is the re-subscribe path (subscribeToTurn).
|
|
3152
|
-
/**
|
|
3153
|
-
* Resubscribe via subscribeToTurn after `execute()`.
|
|
3154
|
-
*
|
|
3155
|
-
* @param opts.afterSequenceNumber - Sequence number to resume SSE subscription after.
|
|
3156
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3157
|
-
* @yields {TurnStreamData} SSE stream items.
|
|
3158
|
-
*/
|
|
3159
|
-
stream(opts, requestOptions) {
|
|
3160
|
-
return __asyncGenerator3(this, arguments, function* stream_1() {
|
|
3161
|
-
yield __await3(yield* __asyncDelegator(__asyncValues3(this.mustGetTurn().stream(opts, requestOptions))));
|
|
3162
|
-
});
|
|
3163
|
-
}
|
|
3164
|
-
/**
|
|
3165
|
-
* Refetch from the server, update state in-place and return self.
|
|
3166
|
-
*
|
|
3167
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3168
|
-
* @returns {this} This prepared turn with updated state.
|
|
3169
|
-
*/
|
|
3170
|
-
refresh(requestOptions) {
|
|
3171
|
-
return __awaiter4(this, void 0, void 0, function* () {
|
|
3172
|
-
yield this.mustGetTurn().refresh(requestOptions);
|
|
3173
|
-
return this;
|
|
3174
|
-
});
|
|
3175
|
-
}
|
|
3176
|
-
/**
|
|
3177
|
-
* Poll getTurn until terminal.
|
|
3178
|
-
*
|
|
3179
|
-
* @param opts.pollIntervalMs - Poll interval ms while waiting. Minimum 3000.
|
|
3180
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3181
|
-
* @returns {TrueFoundryGatewayApi.TurnState} Terminal turn state.
|
|
3182
|
-
*/
|
|
3183
|
-
waitForCompletion(opts, requestOptions) {
|
|
3184
|
-
return __awaiter4(this, void 0, void 0, function* () {
|
|
3185
|
-
return this.mustGetTurn().waitForCompletion(opts, requestOptions);
|
|
3186
|
-
});
|
|
3187
|
-
}
|
|
3188
|
-
/**
|
|
3189
|
-
* Cancel the running last turn for the session.
|
|
3190
|
-
*
|
|
3191
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3192
|
-
* @returns {void}
|
|
3193
|
-
*/
|
|
3194
|
-
cancel(requestOptions) {
|
|
3195
|
-
return __awaiter4(this, void 0, void 0, function* () {
|
|
3196
|
-
return this.mustGetTurn().cancel(requestOptions);
|
|
3197
|
-
});
|
|
3198
|
-
}
|
|
3199
|
-
/**
|
|
3200
|
-
* Paginated turn events; use `stream()` for live SSE.
|
|
3201
|
-
*
|
|
3202
|
-
* @param opts.pageToken - Token from the previous response nextPageToken.
|
|
3203
|
-
* @param opts.limit - Page size. Default 25.
|
|
3204
|
-
* @param opts.order - Sort by creation time. Default `asc`.
|
|
3205
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3206
|
-
* @returns {Promise<core.Page<TrueFoundryGatewayApi.TurnEvent, TrueFoundryGatewayApi.ListEventsResponse>>} Paginated turn events.
|
|
3207
|
-
*/
|
|
3208
|
-
listEvents(opts, requestOptions) {
|
|
3209
|
-
return this.mustGetTurn().listEvents(opts, requestOptions);
|
|
3210
|
-
}
|
|
3211
|
-
// execute(stream:true) path: consume the already-open createTurn SSE (#start), adopting the inner Turn on turn.created.
|
|
3212
|
-
runStreaming() {
|
|
3213
|
-
return __asyncGenerator3(this, arguments, function* runStreaming_1() {
|
|
3214
|
-
yield __await3(yield* __asyncDelegator(__asyncValues3(this.consumeStream(yield __await3(__classPrivateFieldGet2(this, _PreparedTurn_start, "f"))))));
|
|
3215
|
-
});
|
|
3216
|
-
}
|
|
3217
|
-
// execute(stream:false) path: drive the open createTurn SSE until turn.created mints the inner Turn, then poll to terminal.
|
|
3218
|
-
startAndWait(pollIntervalMs, requestOptions) {
|
|
3219
|
-
return __awaiter4(this, void 0, void 0, function* () {
|
|
3220
|
-
const turn = yield this.createTurnIfNotExist();
|
|
3221
|
-
return turn.waitForCompletion({ pollIntervalMs }, requestOptions);
|
|
3222
|
-
});
|
|
3223
|
-
}
|
|
3224
|
-
// Consume an SSE stream, adopting the inner Turn from the first turn.created and yielding all events.
|
|
3225
|
-
// Isolated so a future reconnect wrapper can re-open the stream (subscribeToTurn) on disconnect.
|
|
3226
|
-
// NOTE: reconnect/resume is out of current scope.
|
|
3227
|
-
consumeStream(sse) {
|
|
3228
|
-
return __asyncGenerator3(this, arguments, function* consumeStream_1() {
|
|
3229
|
-
var _a, e_1, _b, _c;
|
|
3230
|
-
try {
|
|
3231
|
-
for (var _d = true, _e = __asyncValues3(sse.withMetadata()), _f; _f = yield __await3(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
3232
|
-
_c = _f.value;
|
|
3233
|
-
_d = false;
|
|
3234
|
-
const { data: event, id } = _c;
|
|
3235
|
-
if (event.type === "turn.created" && __classPrivateFieldGet2(this, _PreparedTurn_turn, "f") == null)
|
|
3236
|
-
this.adoptTurn(event);
|
|
3237
|
-
else if (__classPrivateFieldGet2(this, _PreparedTurn_turn, "f") != null && event.type === "turn.done")
|
|
3238
|
-
this.replaceTurnState(event.state);
|
|
3239
|
-
yield yield __await3({ sequenceNumber: parseSequenceNumber(id), event });
|
|
3240
|
-
}
|
|
3241
|
-
} catch (e_1_1) {
|
|
3242
|
-
e_1 = { error: e_1_1 };
|
|
3243
|
-
} finally {
|
|
3244
|
-
try {
|
|
3245
|
-
if (!_d && !_a && (_b = _e.return)) yield __await3(_b.call(_e));
|
|
3246
|
-
} finally {
|
|
3247
|
-
if (e_1) throw e_1.error;
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
});
|
|
3251
|
-
}
|
|
3252
|
-
// Returns the inner Turn or throws if execute() has not started it yet.
|
|
3253
|
-
mustGetTurn() {
|
|
3254
|
-
if (__classPrivateFieldGet2(this, _PreparedTurn_turn, "f") == null) {
|
|
3255
|
-
throw new Error("Turn not started yet; call execute() first.");
|
|
3256
|
-
}
|
|
3257
|
-
return __classPrivateFieldGet2(this, _PreparedTurn_turn, "f");
|
|
3258
|
-
}
|
|
3259
|
-
// Drive the in-flight createTurn SSE (#start) only until the first turn.created has built the inner
|
|
3260
|
-
// Turn, then break (which closes the underlying SSE via the generator's return()). Returns the Turn.
|
|
3261
|
-
createTurnIfNotExist() {
|
|
3262
|
-
return __awaiter4(this, void 0, void 0, function* () {
|
|
3263
|
-
var _a, e_2, _b, _c;
|
|
3264
|
-
if (__classPrivateFieldGet2(this, _PreparedTurn_turn, "f") == null) {
|
|
3265
|
-
try {
|
|
3266
|
-
for (var _d = true, _e = __asyncValues3(this.consumeStream(yield __classPrivateFieldGet2(this, _PreparedTurn_start, "f"))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
3267
|
-
_c = _f.value;
|
|
3268
|
-
_d = false;
|
|
3269
|
-
const _event = _c;
|
|
3270
|
-
if (__classPrivateFieldGet2(this, _PreparedTurn_turn, "f") != null)
|
|
3271
|
-
break;
|
|
3272
|
-
}
|
|
3273
|
-
} catch (e_2_1) {
|
|
3274
|
-
e_2 = { error: e_2_1 };
|
|
3275
|
-
} finally {
|
|
3276
|
-
try {
|
|
3277
|
-
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
3278
|
-
} finally {
|
|
3279
|
-
if (e_2) throw e_2.error;
|
|
3280
|
-
}
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
return this.mustGetTurn();
|
|
3284
|
-
});
|
|
3285
|
-
}
|
|
3286
|
-
// Open the createTurn SSE with the pending input/previousTurnId. Called synchronously by execute()
|
|
3287
|
-
// so the POST is in flight (and #start latched) before execute returns.
|
|
3288
|
-
openCreateTurn(requestOptions) {
|
|
3289
|
-
return __classPrivateFieldGet2(this, _PreparedTurn_client, "f").agents.sessions.createTurn(this.sessionId, { input: __classPrivateFieldGet2(this, _PreparedTurn_input, "f"), previousTurnId: __classPrivateFieldGet2(this, _PreparedTurn_previousTurnIdInput, "f") }, requestOptions);
|
|
3290
|
-
}
|
|
3291
|
-
// Build the inner Turn directly from the turn.created event (no extra getTurn round trip).
|
|
3292
|
-
// The TurnCreatedEvent member of the TurnStreamingEvent union carries everything Turn needs.
|
|
3293
|
-
// input comes from the request we sent (this.#input), not the event.
|
|
3294
|
-
adoptTurn(event) {
|
|
3295
|
-
__classPrivateFieldSet2(this, _PreparedTurn_turn, new Turn({
|
|
3296
|
-
id: event.turnId,
|
|
3297
|
-
sessionId: this.sessionId,
|
|
3298
|
-
previousTurnId: event.previousTurnId,
|
|
3299
|
-
input: __classPrivateFieldGet2(this, _PreparedTurn_input, "f"),
|
|
3300
|
-
state: event.state,
|
|
3301
|
-
createdBySubject: event.createdBy,
|
|
3302
|
-
createdAt: event.createdAt
|
|
3303
|
-
}, this.session, __classPrivateFieldGet2(this, _PreparedTurn_client, "f")), "f");
|
|
3304
|
-
}
|
|
3305
|
-
// Replace the inner Turn with a fresh one carrying the new state. State changes are rare, so
|
|
3306
|
-
// rebuilding via Turn's own constructor (rather than mutating it) keeps Turn the source of truth.
|
|
3307
|
-
replaceTurnState(state) {
|
|
3308
|
-
const turn = this.mustGetTurn();
|
|
3309
|
-
__classPrivateFieldSet2(this, _PreparedTurn_turn, new Turn({
|
|
3310
|
-
id: turn.id,
|
|
3311
|
-
sessionId: turn.sessionId,
|
|
3312
|
-
previousTurnId: turn.previousTurnId,
|
|
3313
|
-
input: turn.input,
|
|
3314
|
-
state,
|
|
3315
|
-
createdBySubject: turn.createdBySubject,
|
|
3316
|
-
createdAt: turn.createdAt
|
|
3317
|
-
}, this.session, __classPrivateFieldGet2(this, _PreparedTurn_client, "f")), "f");
|
|
3318
|
-
}
|
|
3319
|
-
};
|
|
3320
|
-
_PreparedTurn_client = /* @__PURE__ */ new WeakMap(), _PreparedTurn_input = /* @__PURE__ */ new WeakMap(), _PreparedTurn_previousTurnIdInput = /* @__PURE__ */ new WeakMap(), _PreparedTurn_start = /* @__PURE__ */ new WeakMap(), _PreparedTurn_turn = /* @__PURE__ */ new WeakMap();
|
|
3321
|
-
|
|
3322
|
-
// ../../node_modules/.pnpm/truefoundry-gateway-sdk@0.3.1/node_modules/truefoundry-gateway-sdk/dist/esm/agents/AgentSession.mjs
|
|
3323
|
-
var __awaiter5 = function(thisArg, _arguments, P, generator) {
|
|
3324
|
-
function adopt(value) {
|
|
3325
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
3326
|
-
resolve(value);
|
|
3327
|
-
});
|
|
3328
|
-
}
|
|
3329
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
3330
|
-
function fulfilled(value) {
|
|
3331
|
-
try {
|
|
3332
|
-
step(generator.next(value));
|
|
3333
|
-
} catch (e) {
|
|
3334
|
-
reject(e);
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3337
|
-
function rejected(value) {
|
|
3338
|
-
try {
|
|
3339
|
-
step(generator["throw"](value));
|
|
3340
|
-
} catch (e) {
|
|
3341
|
-
reject(e);
|
|
3342
|
-
}
|
|
3343
|
-
}
|
|
3344
|
-
function step(result) {
|
|
3345
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
3346
|
-
}
|
|
3347
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3348
|
-
});
|
|
3349
|
-
};
|
|
3350
|
-
var __classPrivateFieldSet3 = function(receiver, state, value, kind, f) {
|
|
3351
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3352
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
3353
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
3354
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
3355
|
-
};
|
|
3356
|
-
var __classPrivateFieldGet3 = function(receiver, state, kind, f) {
|
|
3357
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3358
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
3359
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
3360
|
-
};
|
|
3361
|
-
var _AgentSession_client;
|
|
3362
|
-
var AgentSession = class {
|
|
3363
|
-
constructor(session, client) {
|
|
3364
|
-
_AgentSession_client.set(this, void 0);
|
|
3365
|
-
this.id = session.id;
|
|
3366
|
-
this.agentName = session.agentName;
|
|
3367
|
-
this.title = session.title;
|
|
3368
|
-
this.createdBySubject = session.createdBySubject;
|
|
3369
|
-
this.createdAt = session.createdAt;
|
|
3370
|
-
this.updatedAt = session.updatedAt;
|
|
3371
|
-
__classPrivateFieldSet3(this, _AgentSession_client, client, "f");
|
|
3372
|
-
}
|
|
3373
|
-
/**
|
|
3374
|
-
* Stage a turn locally; call `execute()` to start `createTurn`.
|
|
3375
|
-
*
|
|
3376
|
-
* @param opts.input - Turn input items passed to createTurn.
|
|
3377
|
-
* @param opts.previousTurnId - Previous turn to chain from. Default `auto`.
|
|
3378
|
-
* @returns {PreparedTurn} Staged turn.
|
|
3379
|
-
*/
|
|
3380
|
-
prepareTurn(opts) {
|
|
3381
|
-
return new PreparedTurn({ input: opts === null || opts === void 0 ? void 0 : opts.input, previousTurnId: opts === null || opts === void 0 ? void 0 : opts.previousTurnId }, this, __classPrivateFieldGet3(this, _AgentSession_client, "f"));
|
|
3382
|
-
}
|
|
3383
|
-
/**
|
|
3384
|
-
* List turns in this session.
|
|
3385
|
-
*
|
|
3386
|
-
* @param opts.pageToken - Token from the previous response nextPageToken.
|
|
3387
|
-
* @param opts.limit - Page size. Default 10.
|
|
3388
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3389
|
-
* @returns {core.Page<Turn, TrueFoundryGatewayApi.ListTurnsResponse>} Paginated turns.
|
|
3390
|
-
*/
|
|
3391
|
-
listTurns(opts, requestOptions) {
|
|
3392
|
-
return __awaiter5(this, void 0, void 0, function* () {
|
|
3393
|
-
const client = __classPrivateFieldGet3(this, _AgentSession_client, "f");
|
|
3394
|
-
const sessionId = this.id;
|
|
3395
|
-
const page = yield client.agents.sessions.listTurns(sessionId, opts, requestOptions);
|
|
3396
|
-
return new Page({
|
|
3397
|
-
response: page.response,
|
|
3398
|
-
rawResponse: page.rawResponse,
|
|
3399
|
-
hasNextPage: (response) => !!(response === null || response === void 0 ? void 0 : response.pagination.nextPageToken),
|
|
3400
|
-
getItems: (response) => {
|
|
3401
|
-
var _a;
|
|
3402
|
-
return ((_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : []).map((turn) => new Turn(turn, this, client));
|
|
3403
|
-
},
|
|
3404
|
-
loadPage: (response) => HttpResponsePromise.fromPromise(client.agents.sessions.listTurns(sessionId, Object.assign(Object.assign({}, opts), { pageToken: response === null || response === void 0 ? void 0 : response.pagination.nextPageToken }), requestOptions).then((nextPage) => ({ data: nextPage.response, rawResponse: nextPage.rawResponse })))
|
|
3405
|
-
});
|
|
3406
|
-
});
|
|
3407
|
-
}
|
|
3408
|
-
/**
|
|
3409
|
-
* Fetch a turn by ID.
|
|
3410
|
-
*
|
|
3411
|
-
* @param opts.turnId - Unique identifier of the turn to fetch.
|
|
3412
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3413
|
-
* @returns {Turn} Turn data.
|
|
3414
|
-
*/
|
|
3415
|
-
getTurn(opts, requestOptions) {
|
|
3416
|
-
return __awaiter5(this, void 0, void 0, function* () {
|
|
3417
|
-
const response = yield __classPrivateFieldGet3(this, _AgentSession_client, "f").agents.sessions.getTurn(this.id, opts.turnId, requestOptions);
|
|
3418
|
-
return new Turn(response.data, this, __classPrivateFieldGet3(this, _AgentSession_client, "f"));
|
|
3419
|
-
});
|
|
3420
|
-
}
|
|
3421
|
-
/**
|
|
3422
|
-
* Cancel the running last turn for the session.
|
|
3423
|
-
*
|
|
3424
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3425
|
-
* @returns {void}
|
|
3426
|
-
*/
|
|
3427
|
-
cancel(requestOptions) {
|
|
3428
|
-
return __awaiter5(this, void 0, void 0, function* () {
|
|
3429
|
-
yield __classPrivateFieldGet3(this, _AgentSession_client, "f").agents.sessions.cancel(this.id, {}, requestOptions);
|
|
3430
|
-
});
|
|
3431
|
-
}
|
|
3432
|
-
/**
|
|
3433
|
-
* Paginated session events across turns (newest first); subscribe to a running turn for live events.
|
|
3434
|
-
*
|
|
3435
|
-
* @param opts.pageToken - Token from the previous response nextPageToken.
|
|
3436
|
-
* @param opts.lastTurnId - Newest turn in the listing window (initial load only). Omit to use the session last turn.
|
|
3437
|
-
* @param opts.limit - Page size. Default 100.
|
|
3438
|
-
* @param requestOptions - Overrides client timeout, retries, abortSignal, headers, queryParams.
|
|
3439
|
-
* @returns {Promise<core.Page<TrueFoundryGatewayApi.SessionEventItem, TrueFoundryGatewayApi.ListSessionEventsResponse>>} Paginated session events.
|
|
3440
|
-
*/
|
|
3441
|
-
listEvents(opts, requestOptions) {
|
|
3442
|
-
return __classPrivateFieldGet3(this, _AgentSession_client, "f").agents.sessions.listEvents(this.id, opts, requestOptions);
|
|
3443
|
-
}
|
|
3444
|
-
};
|
|
3445
|
-
_AgentSession_client = /* @__PURE__ */ new WeakMap();
|
|
3446
|
-
|
|
3447
2453
|
// src/private/bindDraftAgentSession.ts
|
|
3448
2454
|
var inflightByDraftId = /* @__PURE__ */ new Map();
|
|
3449
|
-
function
|
|
3450
|
-
const internal = client;
|
|
3451
|
-
if (internal.client == null) {
|
|
3452
|
-
throw new Error("AgentSessionClient is missing an internal gateway client.");
|
|
3453
|
-
}
|
|
3454
|
-
return internal.client;
|
|
3455
|
-
}
|
|
3456
|
-
function draftToSessionRecord(draft) {
|
|
3457
|
-
return {
|
|
3458
|
-
id: draft.id,
|
|
3459
|
-
agentName: draft.agentName ?? "",
|
|
3460
|
-
title: draft.title,
|
|
3461
|
-
createdBySubject: draft.createdBySubject,
|
|
3462
|
-
createdAt: draft.createdAt,
|
|
3463
|
-
updatedAt: draft.updatedAt
|
|
3464
|
-
};
|
|
3465
|
-
}
|
|
3466
|
-
async function bindDraftAgentSession(client, gateway, draftSessionId) {
|
|
2455
|
+
async function bindDraftAgentSession(privateClient, draftSessionId) {
|
|
3467
2456
|
let inflight = inflightByDraftId.get(draftSessionId);
|
|
3468
2457
|
if (inflight == null) {
|
|
3469
|
-
inflight = (
|
|
3470
|
-
const response = await gateway.agents.private.draftSessions.get(draftSessionId);
|
|
3471
|
-
return new AgentSession(
|
|
3472
|
-
draftToSessionRecord(response.data),
|
|
3473
|
-
getGatewayFromSessionClient(client)
|
|
3474
|
-
);
|
|
3475
|
-
})().finally(() => {
|
|
2458
|
+
inflight = privateClient.getDraftSession({ draftSessionId }).then((draft) => draft).finally(() => {
|
|
3476
2459
|
if (inflightByDraftId.get(draftSessionId) === inflight) {
|
|
3477
2460
|
inflightByDraftId.delete(draftSessionId);
|
|
3478
2461
|
}
|
|
@@ -3485,8 +2468,8 @@ async function bindDraftAgentSession(client, gateway, draftSessionId) {
|
|
|
3485
2468
|
// src/sessions.ts
|
|
3486
2469
|
var inflightBySessionId = /* @__PURE__ */ new Map();
|
|
3487
2470
|
function getSession(client, sessionId, options) {
|
|
3488
|
-
if (options?.
|
|
3489
|
-
return bindDraftAgentSession(
|
|
2471
|
+
if (options?.privateClient != null) {
|
|
2472
|
+
return bindDraftAgentSession(options.privateClient, sessionId);
|
|
3490
2473
|
}
|
|
3491
2474
|
let inflight = inflightBySessionId.get(sessionId);
|
|
3492
2475
|
if (inflight == null) {
|
|
@@ -3567,15 +2550,15 @@ function resolveTrueFoundryAgentConfig(options) {
|
|
|
3567
2550
|
}
|
|
3568
2551
|
function resolveTrueFoundryAgentRuntimeOptions(options) {
|
|
3569
2552
|
const agent = resolveTrueFoundryAgentConfig(options);
|
|
3570
|
-
if (agent.mode === "draft" && options.
|
|
2553
|
+
if (agent.mode === "draft" && options.privateClient == null) {
|
|
3571
2554
|
throw new Error(
|
|
3572
|
-
"Draft agent mode requires a `
|
|
2555
|
+
"Draft agent mode requires a `privateClient` PrivateAgentSessionClient."
|
|
3573
2556
|
);
|
|
3574
2557
|
}
|
|
3575
2558
|
return {
|
|
3576
2559
|
...options,
|
|
3577
2560
|
agent,
|
|
3578
|
-
|
|
2561
|
+
privateClient: options.privateClient
|
|
3579
2562
|
};
|
|
3580
2563
|
}
|
|
3581
2564
|
|
|
@@ -3787,7 +2770,7 @@ import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMem
|
|
|
3787
2770
|
// src/loadSessionSnapshot.ts
|
|
3788
2771
|
var inflightBySessionId2 = /* @__PURE__ */ new Map();
|
|
3789
2772
|
function loadSessionSnapshot(client, sessionId, sessionOptions, onProgress) {
|
|
3790
|
-
const cacheKey = sessionOptions?.
|
|
2773
|
+
const cacheKey = sessionOptions?.privateClient != null ? `draft:${sessionId}` : sessionId;
|
|
3791
2774
|
let inflight = inflightBySessionId2.get(cacheKey);
|
|
3792
2775
|
if (inflight == null) {
|
|
3793
2776
|
inflight = getSession(client, sessionId, sessionOptions).then(
|
|
@@ -4035,12 +3018,12 @@ function useTrueFoundryAgentMessages({
|
|
|
4035
3018
|
onError,
|
|
4036
3019
|
initializeSession,
|
|
4037
3020
|
resolveConversationSessionId,
|
|
4038
|
-
|
|
3021
|
+
privateClient,
|
|
4039
3022
|
getTurnHeaders
|
|
4040
3023
|
}) {
|
|
4041
3024
|
const sessionOptions = useMemo2(
|
|
4042
|
-
() =>
|
|
4043
|
-
[
|
|
3025
|
+
() => privateClient != null ? { privateClient } : void 0,
|
|
3026
|
+
[privateClient]
|
|
4044
3027
|
);
|
|
4045
3028
|
const [snapshot, setSnapshot] = useState2(createEmptySessionSnapshot);
|
|
4046
3029
|
const [isRunning, setIsRunning] = useState2(false);
|
|
@@ -4581,14 +3564,14 @@ function useTrueFoundryAgentRuntimeImpl(options, pendingAgentSpecRef) {
|
|
|
4581
3564
|
const {
|
|
4582
3565
|
client,
|
|
4583
3566
|
agent,
|
|
4584
|
-
|
|
3567
|
+
privateClient,
|
|
4585
3568
|
adapters,
|
|
4586
3569
|
onError,
|
|
4587
3570
|
listEventsConcurrency,
|
|
4588
3571
|
...sharedOptions
|
|
4589
3572
|
} = options;
|
|
4590
3573
|
const draftBridgeRef = useRef3(
|
|
4591
|
-
agent.mode === "draft" &&
|
|
3574
|
+
agent.mode === "draft" && privateClient != null ? createDraftSessionBridge(privateClient) : null
|
|
4592
3575
|
);
|
|
4593
3576
|
const draftSessionId = useAuiState(
|
|
4594
3577
|
(state) => agent.mode === "draft" ? state.threadListItem.remoteId ?? void 0 : void 0
|
|
@@ -4645,7 +3628,7 @@ function useTrueFoundryAgentRuntimeImpl(options, pendingAgentSpecRef) {
|
|
|
4645
3628
|
listEventsConcurrency,
|
|
4646
3629
|
onError,
|
|
4647
3630
|
initializeSession,
|
|
4648
|
-
|
|
3631
|
+
privateClient: agent.mode === "draft" ? privateClient : void 0,
|
|
4649
3632
|
getTurnHeaders: agent.mode === "draft" ? getTurnHeaders : void 0
|
|
4650
3633
|
});
|
|
4651
3634
|
if (agent.mode === "draft" && draftSpec.agentSpec != null) {
|
|
@@ -4667,9 +3650,9 @@ function useTrueFoundryAgentRuntimeImpl(options, pendingAgentSpecRef) {
|
|
|
4667
3650
|
);
|
|
4668
3651
|
const downloadSandboxFile = useCallback3(
|
|
4669
3652
|
async (path) => {
|
|
4670
|
-
if (
|
|
3653
|
+
if (privateClient == null) {
|
|
4671
3654
|
const error = new Error(
|
|
4672
|
-
"Downloading a sandbox file requires a `
|
|
3655
|
+
"Downloading a sandbox file requires a `privateClient` PrivateAgentSessionClient."
|
|
4673
3656
|
);
|
|
4674
3657
|
onError?.(error);
|
|
4675
3658
|
throw error;
|
|
@@ -4679,10 +3662,11 @@ function useTrueFoundryAgentRuntimeImpl(options, pendingAgentSpecRef) {
|
|
|
4679
3662
|
onError?.(error);
|
|
4680
3663
|
throw error;
|
|
4681
3664
|
}
|
|
3665
|
+
const gateway = getGatewayFromPrivateClient(privateClient);
|
|
4682
3666
|
const response = await gateway.agents.downloadSandboxFile(sandboxId, { path });
|
|
4683
3667
|
return await response.blob();
|
|
4684
3668
|
},
|
|
4685
|
-
[
|
|
3669
|
+
[privateClient, sandboxId, onError]
|
|
4686
3670
|
);
|
|
4687
3671
|
const draftExtras = useMemo3(() => {
|
|
4688
3672
|
if (agent.mode !== "draft") {
|
|
@@ -4767,7 +3751,7 @@ function useTrueFoundryAgentRuntimeImpl(options, pendingAgentSpecRef) {
|
|
|
4767
3751
|
}
|
|
4768
3752
|
function useTrueFoundryAgentRuntime(options) {
|
|
4769
3753
|
const resolved = resolveTrueFoundryAgentRuntimeOptions(options);
|
|
4770
|
-
const { client, agent,
|
|
3754
|
+
const { client, agent, privateClient } = resolved;
|
|
4771
3755
|
const pendingAgentSpecRef = useRef3(
|
|
4772
3756
|
agent.mode === "draft" ? agent.defaultAgentSpec : void 0
|
|
4773
3757
|
);
|
|
@@ -4775,14 +3759,14 @@ function useTrueFoundryAgentRuntime(options) {
|
|
|
4775
3759
|
const namedAgentName = agent.mode === "named" ? agent.agentName : void 0;
|
|
4776
3760
|
const threadListAdapter = useMemo3(() => {
|
|
4777
3761
|
if (agentMode === "draft") {
|
|
4778
|
-
if (
|
|
3762
|
+
if (privateClient == null) {
|
|
4779
3763
|
throw new Error(
|
|
4780
|
-
"Draft agent mode requires a `
|
|
3764
|
+
"Draft agent mode requires a `privateClient` PrivateAgentSessionClient."
|
|
4781
3765
|
);
|
|
4782
3766
|
}
|
|
4783
3767
|
const draftAgent = agent;
|
|
4784
3768
|
return createTrueFoundryDraftThreadListAdapter({
|
|
4785
|
-
|
|
3769
|
+
privateClient,
|
|
4786
3770
|
defaultAgentSpec: draftAgent.defaultAgentSpec,
|
|
4787
3771
|
getAgentSpec: () => pendingAgentSpecRef.current ?? draftAgent.defaultAgentSpec
|
|
4788
3772
|
});
|
|
@@ -4791,7 +3775,7 @@ function useTrueFoundryAgentRuntime(options) {
|
|
|
4791
3775
|
client,
|
|
4792
3776
|
agentName: namedAgentName
|
|
4793
3777
|
});
|
|
4794
|
-
}, [agentMode, namedAgentName, client,
|
|
3778
|
+
}, [agentMode, namedAgentName, client, privateClient]);
|
|
4795
3779
|
return useRemoteThreadListRuntime({
|
|
4796
3780
|
allowNesting: true,
|
|
4797
3781
|
adapter: threadListAdapter,
|
|
@@ -4802,6 +3786,67 @@ function useTrueFoundryAgentRuntime(options) {
|
|
|
4802
3786
|
});
|
|
4803
3787
|
}
|
|
4804
3788
|
|
|
3789
|
+
// src/truefoundryOwnedSessionsThreadListAdapter.ts
|
|
3790
|
+
var THREAD_LIST_PAGE_SIZE3 = 20;
|
|
3791
|
+
function ownedSessionTitle(session) {
|
|
3792
|
+
if (session.type === "session/draft") {
|
|
3793
|
+
return draftSessionTitle(session);
|
|
3794
|
+
}
|
|
3795
|
+
return session.title ?? session.agentName;
|
|
3796
|
+
}
|
|
3797
|
+
function createTrueFoundryOwnedSessionsThreadListAdapter(options) {
|
|
3798
|
+
const { privateClient } = options;
|
|
3799
|
+
return {
|
|
3800
|
+
async list({ after } = {}) {
|
|
3801
|
+
const page = await privateClient.listOwnedSessions({
|
|
3802
|
+
limit: THREAD_LIST_PAGE_SIZE3,
|
|
3803
|
+
pageToken: after,
|
|
3804
|
+
startTimestamp: sessionListStartTimestamp()
|
|
3805
|
+
});
|
|
3806
|
+
const threads = page.data.map((session) => ({
|
|
3807
|
+
status: "regular",
|
|
3808
|
+
remoteId: session.id,
|
|
3809
|
+
title: ownedSessionTitle(session),
|
|
3810
|
+
lastMessageAt: new Date(session.updatedAt)
|
|
3811
|
+
}));
|
|
3812
|
+
return {
|
|
3813
|
+
threads,
|
|
3814
|
+
nextCursor: page.response.pagination.nextPageToken ?? void 0
|
|
3815
|
+
};
|
|
3816
|
+
},
|
|
3817
|
+
async initialize() {
|
|
3818
|
+
throw new Error(
|
|
3819
|
+
"Owned sessions history adapter is read-only; create sessions via a named or draft runtime."
|
|
3820
|
+
);
|
|
3821
|
+
},
|
|
3822
|
+
async fetch(remoteId) {
|
|
3823
|
+
const draft = await privateClient.getDraftSession({
|
|
3824
|
+
draftSessionId: remoteId
|
|
3825
|
+
});
|
|
3826
|
+
return {
|
|
3827
|
+
status: "regular",
|
|
3828
|
+
remoteId: draft.id,
|
|
3829
|
+
title: draftSessionTitle(draft),
|
|
3830
|
+
lastMessageAt: new Date(draft.updatedAt)
|
|
3831
|
+
};
|
|
3832
|
+
},
|
|
3833
|
+
async rename() {
|
|
3834
|
+
},
|
|
3835
|
+
async archive() {
|
|
3836
|
+
},
|
|
3837
|
+
async unarchive() {
|
|
3838
|
+
},
|
|
3839
|
+
async delete() {
|
|
3840
|
+
},
|
|
3841
|
+
async generateTitle() {
|
|
3842
|
+
return new ReadableStream();
|
|
3843
|
+
}
|
|
3844
|
+
};
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
// src/index.ts
|
|
3848
|
+
import { PrivateAgentSessionClient } from "truefoundry-gateway-sdk/agents/private";
|
|
3849
|
+
|
|
4805
3850
|
// src/hooks.ts
|
|
4806
3851
|
import { useMemo as useMemo4 } from "react";
|
|
4807
3852
|
import { useAui as useAui2 } from "@assistant-ui/store";
|
|
@@ -4946,6 +3991,7 @@ var trueFoundryAttachmentAdapter = {
|
|
|
4946
3991
|
}
|
|
4947
3992
|
};
|
|
4948
3993
|
export {
|
|
3994
|
+
PrivateAgentSessionClient,
|
|
4949
3995
|
ROOT_THREAD_ID,
|
|
4950
3996
|
TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY,
|
|
4951
3997
|
buildEditedUserMessageContent,
|
|
@@ -4957,6 +4003,7 @@ export {
|
|
|
4957
4003
|
convertTurnsToThreadMessages,
|
|
4958
4004
|
createDraftSessionBridge,
|
|
4959
4005
|
createTrueFoundryDraftThreadListAdapter,
|
|
4006
|
+
createTrueFoundryOwnedSessionsThreadListAdapter,
|
|
4960
4007
|
createTrueFoundryThreadListAdapter,
|
|
4961
4008
|
draftSessionTitle,
|
|
4962
4009
|
findPausedAssistantMessage,
|