@feltdb/feltkit 0.3.37 → 0.4.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/app.d.ts +153 -3
- package/dist/app.js +159 -7
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js +21 -0
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +4 -0
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/client/index.d.ts +189 -0
- package/dist/client/index.js +201 -0
- package/dist/client/index.js.map +1 -1
- package/dist/clock.d.ts +24 -0
- package/dist/clock.js +49 -0
- package/dist/clock.js.map +1 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -0
- package/dist/docs.js.map +1 -1
- package/dist/event-stage.js +2 -0
- package/dist/event-stage.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +9 -1
- package/dist/policy.js +16 -3
- package/dist/policy.js.map +1 -1
- package/dist/presence.d.ts +85 -0
- package/dist/presence.js +37 -0
- package/dist/presence.js.map +1 -0
- package/dist/quota.d.ts +72 -0
- package/dist/quota.js +143 -0
- package/dist/quota.js.map +1 -0
- package/dist/react/agent-control.d.ts +189 -0
- package/dist/react/agent-control.js +366 -0
- package/dist/react/agent-control.js.map +1 -0
- package/dist/react/index.d.ts +14 -1
- package/dist/react/index.js +41 -0
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/activity.d.ts +8 -0
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent-control.d.ts +18 -0
- package/dist/runtime/agent-control.js +34 -1
- package/dist/runtime/agent-control.js.map +1 -1
- package/dist/runtime/agent.js +16 -4
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/assemble.js +1 -1
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/authority.d.ts +38 -0
- package/dist/runtime/authority.js +13 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/capabilities.js +2 -1
- package/dist/runtime/capabilities.js.map +1 -1
- package/dist/runtime/changes.d.ts +17 -0
- package/dist/runtime/changes.js +65 -2
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/context.d.ts +114 -0
- package/dist/runtime/contract.js +9 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/events.js +17 -1
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/integrations.js +7 -7
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +19 -2
- package/dist/runtime/invocations.js +16 -3
- package/dist/runtime/invocations.js.map +1 -1
- package/dist/runtime/policies.d.ts +5 -2
- package/dist/runtime/policies.js.map +1 -1
- package/dist/runtime/presence-host.d.ts +84 -0
- package/dist/runtime/presence-host.js +303 -0
- package/dist/runtime/presence-host.js.map +1 -0
- package/dist/runtime/providers.d.ts +5 -1
- package/dist/runtime/providers.js +11 -5
- package/dist/runtime/providers.js.map +1 -1
- package/dist/runtime/resource-access.d.ts +137 -0
- package/dist/runtime/resource-access.js +177 -0
- package/dist/runtime/resource-access.js.map +1 -0
- package/dist/runtime/runtime.d.ts +73 -0
- package/dist/runtime/runtime.js +594 -37
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/sessions.d.ts +11 -0
- package/dist/runtime/sessions.js +15 -0
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +59 -0
- package/dist/runtime/tenancy.js +128 -0
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/workers.d.ts +123 -0
- package/dist/runtime/workers.js +291 -0
- package/dist/runtime/workers.js.map +1 -0
- package/dist/server/index.d.ts +0 -19
- package/dist/server/index.js +44 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.d.ts +8 -15
- package/dist/server/mcp.js +40 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/project.js +6 -5
- package/dist/server/project.js.map +1 -1
- package/dist/server/tenancy.d.ts +7 -0
- package/dist/server/tenancy.js +31 -0
- package/dist/server/tenancy.js.map +1 -1
- package/dist/server/watch.d.ts +10 -0
- package/dist/server/watch.js +88 -0
- package/dist/server/watch.js.map +1 -0
- package/dist/testing/index.d.ts +3 -1
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-CONTROL.md +130 -4
- package/docs/APPBOUNDRY.md +37 -0
- package/docs/ARCHITECTURE.md +6 -2
- package/docs/AUTH.md +35 -0
- package/docs/COMPONENTS.md +71 -0
- package/docs/GUARANTEES.md +4 -4
- package/docs/PRESENCE-AND-SIGNALING-PROPOSAL.md +152 -0
- package/docs/README.md +3 -2
- package/docs/SECURITY.md +71 -3
- package/docs/TRANSACTIONS.md +48 -0
- package/docs/UPSTREAM-GAPS.md +16 -2
- package/package.json +13 -13
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-agent/SKILL.md +1 -1
- package/skills/feltkit-build/SKILL.md +11 -1
- package/skills/feltkit-data/SKILL.md +1 -1
- package/skills/feltkit-operations/SKILL.md +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -256,6 +256,53 @@ export interface ActionStreamOptions {
|
|
|
256
256
|
signal?: AbortSignal;
|
|
257
257
|
}
|
|
258
258
|
/** An agent action of the signed-in person, as /api/agent/actions shows it. */
|
|
259
|
+
/**
|
|
260
|
+
* What happened to one of your calls (AppPort `appport.invocation.status@1`, spec §13.5), from the runtime's
|
|
261
|
+
* records: `succeeded`, `failed`, `unknown` (an effect started and has no definite outcome; settle it before doing
|
|
262
|
+
* anything else), `in_progress` (claimed, no answer yet), `unrecorded` (nothing is recorded: never arrived, refused,
|
|
263
|
+
* or failed with a known outcome; a retry with the same idempotency key runs it).
|
|
264
|
+
*/
|
|
265
|
+
export interface InvocationStatus {
|
|
266
|
+
status: "succeeded" | "failed" | "unknown" | "in_progress" | "unrecorded";
|
|
267
|
+
requestId?: string;
|
|
268
|
+
capability?: {
|
|
269
|
+
name: string;
|
|
270
|
+
version: number;
|
|
271
|
+
};
|
|
272
|
+
output?: unknown;
|
|
273
|
+
error?: {
|
|
274
|
+
code: string;
|
|
275
|
+
message: string;
|
|
276
|
+
details?: unknown;
|
|
277
|
+
};
|
|
278
|
+
effect?: {
|
|
279
|
+
outcome?: "succeeded" | "failed" | "unknown";
|
|
280
|
+
startedAt: string;
|
|
281
|
+
finishedAt?: string;
|
|
282
|
+
};
|
|
283
|
+
settlement?: {
|
|
284
|
+
outcome: "succeeded" | "failed";
|
|
285
|
+
determinedBy: "verification" | "person";
|
|
286
|
+
settledAt: string;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/** Name one call: its request id, or the idempotency key you sent with the capability it was for. */
|
|
290
|
+
export type InvocationStatusQuery = {
|
|
291
|
+
requestId: string;
|
|
292
|
+
} | {
|
|
293
|
+
idempotencyKey: string;
|
|
294
|
+
capability: {
|
|
295
|
+
name: string;
|
|
296
|
+
version?: number;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Whether an error says the call may or may not have taken effect (an external effect with no definite answer):
|
|
301
|
+
* never repeat it blindly; ask `client.invocationStatus` and settle it.
|
|
302
|
+
*/
|
|
303
|
+
export declare function isOutcomeUnknown(error: unknown): boolean;
|
|
304
|
+
/** The call an unknown outcome is about (its request id), when the error names it. */
|
|
305
|
+
export declare function unknownCallId(error: unknown): string | undefined;
|
|
259
306
|
export interface OwnAction {
|
|
260
307
|
taskId: string;
|
|
261
308
|
objective?: string;
|
|
@@ -289,6 +336,65 @@ export interface OwnAction {
|
|
|
289
336
|
/** What an approval binds to: the operation and its exact input. Send it back with approveAction. */
|
|
290
337
|
inputDigest?: string;
|
|
291
338
|
}
|
|
339
|
+
/** The derived phase of a steered agent task (docs/AGENT-CONTROL.md). Reported by the server, never guessed. */
|
|
340
|
+
export type AgentControlPhase = "running" | "pausing" | "paused" | "interrupted" | "blocked" | "completed" | "stopped";
|
|
341
|
+
export type AgentUpdateState = "signaled" | "received" | "delivered" | "incorporated" | "conflict" | "withdrawn" | "abandoned";
|
|
342
|
+
/** One update a person sent an agent, as the server records it. */
|
|
343
|
+
export interface AgentUpdate {
|
|
344
|
+
instructionId: string;
|
|
345
|
+
taskId: string;
|
|
346
|
+
state: AgentUpdateState;
|
|
347
|
+
seq: number;
|
|
348
|
+
/** Who signaled or submitted it (`type:id`). */
|
|
349
|
+
from: string;
|
|
350
|
+
text?: string;
|
|
351
|
+
note?: string;
|
|
352
|
+
signaledAt?: string;
|
|
353
|
+
receivedAt?: string;
|
|
354
|
+
deliveredAt?: string;
|
|
355
|
+
deliveredAtCheckpoint?: number;
|
|
356
|
+
resolvedAt?: string;
|
|
357
|
+
/** incorporated / conflict: what the agent said; withdrawn / abandoned: why. */
|
|
358
|
+
resolution?: {
|
|
359
|
+
by: string;
|
|
360
|
+
note: string;
|
|
361
|
+
};
|
|
362
|
+
history: Array<{
|
|
363
|
+
state: AgentUpdateState;
|
|
364
|
+
at: string;
|
|
365
|
+
by: string;
|
|
366
|
+
note?: string;
|
|
367
|
+
}>;
|
|
368
|
+
}
|
|
369
|
+
/** A task's control state: `GET /api/agent/tasks/:id/control`, and every `control` frame of its event stream. */
|
|
370
|
+
export interface AgentControlState {
|
|
371
|
+
taskId: string;
|
|
372
|
+
objective: string;
|
|
373
|
+
owner: string;
|
|
374
|
+
phase: AgentControlPhase;
|
|
375
|
+
mode: "running" | "paused" | "interrupted";
|
|
376
|
+
reason: string | null;
|
|
377
|
+
inFlight: {
|
|
378
|
+
generations: string[];
|
|
379
|
+
actions: string[];
|
|
380
|
+
};
|
|
381
|
+
/** Updates signaled and not yet submitted. */
|
|
382
|
+
signaled: number;
|
|
383
|
+
/** Every update, oldest first. */
|
|
384
|
+
instructions: AgentUpdate[];
|
|
385
|
+
checkpoint: number;
|
|
386
|
+
/** Changes whenever anything changes. */
|
|
387
|
+
revision: string;
|
|
388
|
+
}
|
|
389
|
+
/** A tenant's public branding (K5), as `resolveTenant` answers it. */
|
|
390
|
+
export interface TenantBranding {
|
|
391
|
+
displayName?: string;
|
|
392
|
+
logoUrl?: string;
|
|
393
|
+
primaryColor?: string;
|
|
394
|
+
accentColor?: string;
|
|
395
|
+
backgroundColor?: string;
|
|
396
|
+
tagline?: string;
|
|
397
|
+
}
|
|
292
398
|
/** `keys`: per collection, opaque keys of the changed records (absent: the whole collection may have changed). */
|
|
293
399
|
type ChangeListener = (collections: string[], keys?: Record<string, string[]>) => void;
|
|
294
400
|
/** A query's read set: collections read wholly, and opaque predicate keys by collection. */
|
|
@@ -343,6 +449,28 @@ export declare class FeltKitClient {
|
|
|
343
449
|
version?: number;
|
|
344
450
|
idempotencyKey?: string;
|
|
345
451
|
}): Promise<T>;
|
|
452
|
+
/**
|
|
453
|
+
* What happened to one of your calls (`appport.invocation.status@1`): by the request id an unknown outcome named
|
|
454
|
+
* (`unknownCallId(error)`, or the `requestId` a call returned), or by the idempotency key you sent. Only your own
|
|
455
|
+
* calls are answered; anyone else's reads `unrecorded`. It never runs anything.
|
|
456
|
+
*/
|
|
457
|
+
invocationStatus(query: InvocationStatusQuery): Promise<InvocationStatus>;
|
|
458
|
+
/** Ask the external system what happened to an unknown call (its capability's `verify`); a definite answer settles it. */
|
|
459
|
+
verifyCall(callId: string): Promise<{
|
|
460
|
+
verification: {
|
|
461
|
+
outcome: "succeeded" | "failed" | "unknown";
|
|
462
|
+
evidence?: unknown;
|
|
463
|
+
reason?: string;
|
|
464
|
+
};
|
|
465
|
+
}>;
|
|
466
|
+
/**
|
|
467
|
+
* Settle an unknown call, saying what you checked. Only a person who may make the call settles it, once; the external
|
|
468
|
+
* system's answer comes first (a contradicting decision is refused). Nothing runs.
|
|
469
|
+
*/
|
|
470
|
+
settleCall(callId: string, input: {
|
|
471
|
+
outcome: "succeeded" | "failed";
|
|
472
|
+
note: string;
|
|
473
|
+
}): Promise<void>;
|
|
346
474
|
/** Run a mutation. Resolves after its writes have committed. */
|
|
347
475
|
mutation<F extends FunctionReference<"mutation">>(fn: F, args?: ArgsOf<F>): Promise<ResultOf<F>>;
|
|
348
476
|
/**
|
|
@@ -369,6 +497,32 @@ export declare class FeltKitClient {
|
|
|
369
497
|
}): Promise<OwnAction | null>;
|
|
370
498
|
/** Reject one of your own proposed actions. Nothing runs. */
|
|
371
499
|
rejectAction(taskId: string, actionId: string, reason?: string): Promise<OwnAction | null>;
|
|
500
|
+
/** The task's control state now. */
|
|
501
|
+
agentControl(taskId: string): Promise<AgentControlState>;
|
|
502
|
+
/** Say an update is coming. The agent keeps working. Returns the signaled update (fill it with `submitAgentUpdate({ instructionId })`). */
|
|
503
|
+
signalAgentUpdate(taskId: string, options?: {
|
|
504
|
+
note?: string;
|
|
505
|
+
idempotencyKey?: string;
|
|
506
|
+
}): Promise<AgentUpdate>;
|
|
507
|
+
/**
|
|
508
|
+
* Send an update. It is *received* (stored) when this resolves, not yet incorporated. `instructionId` fills your own
|
|
509
|
+
* signal; `idempotencyKey` makes a retry (or a double click) the same update: the same key with other text is refused
|
|
510
|
+
* (IDEMPOTENCY_KEY_REUSED).
|
|
511
|
+
*/
|
|
512
|
+
submitAgentUpdate(taskId: string, text: string, options?: {
|
|
513
|
+
instructionId?: string;
|
|
514
|
+
idempotencyKey?: string;
|
|
515
|
+
}): Promise<AgentUpdate>;
|
|
516
|
+
/** Take back a signaled or received update (its sender or the task owner). */
|
|
517
|
+
withdrawAgentUpdate(taskId: string, instructionId: string, reason?: string): Promise<AgentUpdate>;
|
|
518
|
+
/** pause, resume, interrupt or stop the task. Answers the state after the change, as the server reads it back. */
|
|
519
|
+
controlAgent(taskId: string, op: "pause" | "resume" | "interrupt" | "stop", reason?: string): Promise<AgentControlState>;
|
|
520
|
+
/**
|
|
521
|
+
* Follow a task's control state live (`GET …/control/events`). Level-triggered: `listener` gets the whole state on
|
|
522
|
+
* connect and after every change; a frame whose revision is one already shown, or that arrives out of order after a
|
|
523
|
+
* newer one, is dropped. Reconnects after a dropped stream; stops on a refusal (signed out, no access). Returns stop().
|
|
524
|
+
*/
|
|
525
|
+
watchAgentControl(taskId: string, listener: (state: AgentControlState) => void, onError?: (error: FeltKitClientError) => void): () => void;
|
|
372
526
|
session(): Promise<SessionInfo>;
|
|
373
527
|
/** Development only: sign in as a dev user declared in feltkit({ dev: { users } }). */
|
|
374
528
|
signInAsDevUser(userId: string): Promise<SessionInfo["principal"]>;
|
|
@@ -438,6 +592,33 @@ export declare class FeltKitClient {
|
|
|
438
592
|
/** Leave the current tenant; the session moves to your next one (or none). */
|
|
439
593
|
leaveTenant(): Promise<TenantInfo | null>;
|
|
440
594
|
renameTenant(name: string): Promise<void>;
|
|
595
|
+
/**
|
|
596
|
+
* Which tenant a slug or custom domain names, as its public branding (K5). No sign-in needed: for a join or
|
|
597
|
+
* sign-in page that must be branded first. With neither, the page's own host. Null when nothing matches.
|
|
598
|
+
*/
|
|
599
|
+
resolveTenant(by?: {
|
|
600
|
+
slug?: string;
|
|
601
|
+
domain?: string;
|
|
602
|
+
}): Promise<{
|
|
603
|
+
slug: string | null;
|
|
604
|
+
branding: TenantBranding;
|
|
605
|
+
} | null>;
|
|
606
|
+
/** The current tenant's slug, custom domains and branding (members). */
|
|
607
|
+
tenantPublic(): Promise<{
|
|
608
|
+
slug: string | null;
|
|
609
|
+
domains: string[];
|
|
610
|
+
branding: TenantBranding;
|
|
611
|
+
}>;
|
|
612
|
+
/** Set the current tenant's slug, domains and branding (tenant.update); null clears one. */
|
|
613
|
+
setTenantPublic(input: {
|
|
614
|
+
slug?: string | null;
|
|
615
|
+
domains?: string[] | null;
|
|
616
|
+
branding?: TenantBranding | null;
|
|
617
|
+
}): Promise<{
|
|
618
|
+
slug: string | null;
|
|
619
|
+
domains: string[];
|
|
620
|
+
branding: TenantBranding;
|
|
621
|
+
}>;
|
|
441
622
|
invitations(): Promise<InvitationInfo[]>;
|
|
442
623
|
/** Invite an address with a role. `link` is the invitation link (to share yourself); `sent` says whether it was e-mailed. */
|
|
443
624
|
invite(input: {
|
|
@@ -528,4 +709,12 @@ export declare function waitOrWake(ms: number, signal: AbortSignal, target?: {
|
|
|
528
709
|
removeEventListener?: (t: string, l: () => void) => void;
|
|
529
710
|
} | undefined): Promise<boolean>;
|
|
530
711
|
export declare function createClient(options?: ClientOptions): FeltKitClient;
|
|
712
|
+
/**
|
|
713
|
+
* Which control frames to show. A revision is a digest, not a counter, so order comes from the state itself: the
|
|
714
|
+
* checkpoint count and every record's sequence only grow. A frame is stale when it shows nothing newer than the
|
|
715
|
+
* last one shown and something older; a frame that repeats the last revision changes nothing.
|
|
716
|
+
*/
|
|
717
|
+
export declare function controlRevisions(): {
|
|
718
|
+
accept(state: AgentControlState): boolean;
|
|
719
|
+
};
|
|
531
720
|
export {};
|
package/dist/client/index.js
CHANGED
|
@@ -87,6 +87,19 @@ function extensionIdentityApi() {
|
|
|
87
87
|
const identity = globalThis.chrome?.identity;
|
|
88
88
|
return identity && typeof identity.launchWebAuthFlow === "function" && typeof identity.getRedirectURL === "function" ? identity : null;
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether an error says the call may or may not have taken effect (an external effect with no definite answer):
|
|
92
|
+
* never repeat it blindly; ask `client.invocationStatus` and settle it.
|
|
93
|
+
*/
|
|
94
|
+
export function isOutcomeUnknown(error) {
|
|
95
|
+
const e = error;
|
|
96
|
+
return !!e && (e.code === "OUTCOME_UNKNOWN" || e.details?.reason === "EFFECT_OUTCOME_UNKNOWN" || e.details?.reason === "IDEMPOTENCY_OUTCOME_UNKNOWN");
|
|
97
|
+
}
|
|
98
|
+
/** The call an unknown outcome is about (its request id), when the error names it. */
|
|
99
|
+
export function unknownCallId(error) {
|
|
100
|
+
const id = error?.details?.callId;
|
|
101
|
+
return typeof id === "string" ? id : undefined;
|
|
102
|
+
}
|
|
90
103
|
/** A token store that holds nothing: in cookie mode the browser keeps the session, not the page. */
|
|
91
104
|
function noTokens() {
|
|
92
105
|
return { get: () => null, set: () => undefined };
|
|
@@ -284,6 +297,26 @@ export class FeltKitClient {
|
|
|
284
297
|
async invoke(capability, input = {}, options = {}) {
|
|
285
298
|
return (await this.#post(`/api/capability/${encodeURIComponent(capability)}`, { input, ...(options.version ? { version: options.version } : {}), ...(options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}) })).value;
|
|
286
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* What happened to one of your calls (`appport.invocation.status@1`): by the request id an unknown outcome named
|
|
302
|
+
* (`unknownCallId(error)`, or the `requestId` a call returned), or by the idempotency key you sent. Only your own
|
|
303
|
+
* calls are answered; anyone else's reads `unrecorded`. It never runs anything.
|
|
304
|
+
*/
|
|
305
|
+
async invocationStatus(query) {
|
|
306
|
+
const input = "requestId" in query ? { requestId: query.requestId } : { idempotencyKey: query.idempotencyKey, capability: { name: query.capability.name, version: query.capability.version ?? 1 } };
|
|
307
|
+
return this.invoke("appport.invocation.status", input);
|
|
308
|
+
}
|
|
309
|
+
/** Ask the external system what happened to an unknown call (its capability's `verify`); a definite answer settles it. */
|
|
310
|
+
async verifyCall(callId) {
|
|
311
|
+
return this.#post(`/api/provider-calls/${encodeURIComponent(callId)}/verify`, {});
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Settle an unknown call, saying what you checked. Only a person who may make the call settles it, once; the external
|
|
315
|
+
* system's answer comes first (a contradicting decision is refused). Nothing runs.
|
|
316
|
+
*/
|
|
317
|
+
async settleCall(callId, input) {
|
|
318
|
+
await this.#post(`/api/provider-calls/${encodeURIComponent(callId)}/settle`, input);
|
|
319
|
+
}
|
|
287
320
|
/** Run a mutation. Resolves after its writes have committed. */
|
|
288
321
|
async mutation(fn, args) {
|
|
289
322
|
return (await this.#post(`/api/mutation/${encodeURIComponent(fn.name)}`, { args: args ?? {} })).value;
|
|
@@ -433,6 +466,108 @@ export class FeltKitClient {
|
|
|
433
466
|
const payload = await this.#post("/api/agent/actions/reject", { taskId, actionId, ...(reason ? { reason } : {}) });
|
|
434
467
|
return payload.action ? { taskId, ...payload.action } : null;
|
|
435
468
|
}
|
|
469
|
+
// ---- Agent control: steer a running agent task (docs/AGENT-CONTROL.md) ----------------
|
|
470
|
+
/** The task's control state now. */
|
|
471
|
+
async agentControl(taskId) {
|
|
472
|
+
await this.#upgrade;
|
|
473
|
+
const sent = this.tokens.get();
|
|
474
|
+
const response = await this.#fetch(`${this.url}/api/agent/tasks/${encodeURIComponent(taskId)}/control`, { credentials: "same-origin", headers: this.#headers() });
|
|
475
|
+
const payload = (await response.json().catch(() => null));
|
|
476
|
+
if (!payload?.ok) {
|
|
477
|
+
this.#sessionEnded(payload?.error, sent);
|
|
478
|
+
throw new FeltKitClientError(payload?.error ?? { code: "INTERNAL", message: `The control state answered ${response.status}.` });
|
|
479
|
+
}
|
|
480
|
+
return payload.control;
|
|
481
|
+
}
|
|
482
|
+
/** Say an update is coming. The agent keeps working. Returns the signaled update (fill it with `submitAgentUpdate({ instructionId })`). */
|
|
483
|
+
async signalAgentUpdate(taskId, options = {}) {
|
|
484
|
+
const payload = await this.#post(`/api/agent/tasks/${encodeURIComponent(taskId)}/control/signal`, { ...(options.note ? { note: options.note } : {}), ...(options.idempotencyKey ? { key: options.idempotencyKey } : {}) });
|
|
485
|
+
return payload.instruction;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Send an update. It is *received* (stored) when this resolves, not yet incorporated. `instructionId` fills your own
|
|
489
|
+
* signal; `idempotencyKey` makes a retry (or a double click) the same update: the same key with other text is refused
|
|
490
|
+
* (IDEMPOTENCY_KEY_REUSED).
|
|
491
|
+
*/
|
|
492
|
+
async submitAgentUpdate(taskId, text, options = {}) {
|
|
493
|
+
const payload = await this.#post(`/api/agent/tasks/${encodeURIComponent(taskId)}/control/submit`, { text, ...(options.instructionId ? { instructionId: options.instructionId } : {}), ...(options.idempotencyKey ? { key: options.idempotencyKey } : {}) });
|
|
494
|
+
return payload.instruction;
|
|
495
|
+
}
|
|
496
|
+
/** Take back a signaled or received update (its sender or the task owner). */
|
|
497
|
+
async withdrawAgentUpdate(taskId, instructionId, reason) {
|
|
498
|
+
const payload = await this.#post(`/api/agent/tasks/${encodeURIComponent(taskId)}/control/withdraw`, { instructionId, ...(reason ? { reason } : {}) });
|
|
499
|
+
return payload.instruction;
|
|
500
|
+
}
|
|
501
|
+
/** pause, resume, interrupt or stop the task. Answers the state after the change, as the server reads it back. */
|
|
502
|
+
async controlAgent(taskId, op, reason) {
|
|
503
|
+
const payload = await this.#post(`/api/agent/tasks/${encodeURIComponent(taskId)}/control/${op}`, reason ? { reason } : {});
|
|
504
|
+
return payload.control;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Follow a task's control state live (`GET …/control/events`). Level-triggered: `listener` gets the whole state on
|
|
508
|
+
* connect and after every change; a frame whose revision is one already shown, or that arrives out of order after a
|
|
509
|
+
* newer one, is dropped. Reconnects after a dropped stream; stops on a refusal (signed out, no access). Returns stop().
|
|
510
|
+
*/
|
|
511
|
+
watchAgentControl(taskId, listener, onError) {
|
|
512
|
+
const controller = new AbortController();
|
|
513
|
+
let attempt = 0;
|
|
514
|
+
let sent = null;
|
|
515
|
+
const tracker = controlRevisions();
|
|
516
|
+
const run = async () => {
|
|
517
|
+
while (!controller.signal.aborted) {
|
|
518
|
+
try {
|
|
519
|
+
await this.#upgrade;
|
|
520
|
+
sent = this.tokens.get();
|
|
521
|
+
const response = await this.#fetch(`${this.url}/api/agent/tasks/${encodeURIComponent(taskId)}/control/events`, { credentials: "same-origin", headers: { ...this.#headers(), Accept: "text/event-stream" }, signal: controller.signal });
|
|
522
|
+
if (!response.ok || !response.body) {
|
|
523
|
+
const payload = await response.json().catch(() => null);
|
|
524
|
+
this.#sessionEnded(payload?.error, sent);
|
|
525
|
+
throw new FeltKitClientError(payload?.error ?? { code: "UNAVAILABLE", message: `The control stream answered ${response.status}.` });
|
|
526
|
+
}
|
|
527
|
+
attempt = 0;
|
|
528
|
+
const reader = response.body.getReader();
|
|
529
|
+
const decoder = new TextDecoder();
|
|
530
|
+
let buffer = "";
|
|
531
|
+
for (;;) {
|
|
532
|
+
const { value, done } = await reader.read();
|
|
533
|
+
if (done)
|
|
534
|
+
break;
|
|
535
|
+
buffer += decoder.decode(value, { stream: true });
|
|
536
|
+
let index;
|
|
537
|
+
while ((index = buffer.indexOf("\n\n")) >= 0) {
|
|
538
|
+
const raw = buffer.slice(0, index);
|
|
539
|
+
buffer = buffer.slice(index + 2);
|
|
540
|
+
const event = /^event: (.+)$/m.exec(raw)?.[1];
|
|
541
|
+
const data = /^data: (.+)$/m.exec(raw)?.[1];
|
|
542
|
+
if (event === "control" && data) {
|
|
543
|
+
const state = JSON.parse(data).control;
|
|
544
|
+
if (tracker.accept(state))
|
|
545
|
+
listener(state);
|
|
546
|
+
}
|
|
547
|
+
if (event === "error" && data) {
|
|
548
|
+
const error = JSON.parse(data).error;
|
|
549
|
+
if (this.#sessionEnded(error, sent))
|
|
550
|
+
throw new FeltKitClientError(error);
|
|
551
|
+
onError?.(new FeltKitClientError(error));
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
if (controller.signal.aborted)
|
|
558
|
+
return;
|
|
559
|
+
if (error instanceof FeltKitClientError && (error.code === "UNAUTHORIZED" || error.code === "FORBIDDEN" || error.code === "NOT_FOUND")) {
|
|
560
|
+
onError?.(error);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
attempt += 1;
|
|
565
|
+
await new Promise((r) => setTimeout(r, Math.min(500 * 2 ** attempt, 15_000)));
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
void run();
|
|
569
|
+
return () => controller.abort();
|
|
570
|
+
}
|
|
436
571
|
async session() {
|
|
437
572
|
await this.#upgrade;
|
|
438
573
|
const response = await this.#fetch(`${this.url}/api/session`, { credentials: "same-origin", headers: this.#headers() });
|
|
@@ -590,6 +725,34 @@ export class FeltKitClient {
|
|
|
590
725
|
await this.#post("/api/tenants/current/rename", { name });
|
|
591
726
|
this.#notifySession();
|
|
592
727
|
}
|
|
728
|
+
/**
|
|
729
|
+
* Which tenant a slug or custom domain names, as its public branding (K5). No sign-in needed: for a join or
|
|
730
|
+
* sign-in page that must be branded first. With neither, the page's own host. Null when nothing matches.
|
|
731
|
+
*/
|
|
732
|
+
async resolveTenant(by = {}) {
|
|
733
|
+
const query = new URLSearchParams({ ...(by.slug ? { slug: by.slug } : {}), ...(by.domain ? { domain: by.domain } : {}) });
|
|
734
|
+
const response = await this.#fetch(`${this.url}/api/tenants/resolve${query.size ? `?${query}` : ""}`, { credentials: "omit" });
|
|
735
|
+
if (response.status === 404)
|
|
736
|
+
return null;
|
|
737
|
+
const payload = (await response.json().catch(() => null));
|
|
738
|
+
if (!payload?.ok)
|
|
739
|
+
throw new FeltKitClientError(payload?.error ?? { code: "INTERNAL", message: `Tenant resolution answered ${response.status}.` });
|
|
740
|
+
return payload.tenant;
|
|
741
|
+
}
|
|
742
|
+
/** The current tenant's slug, custom domains and branding (members). */
|
|
743
|
+
async tenantPublic() {
|
|
744
|
+
await this.#upgrade;
|
|
745
|
+
const response = await this.#fetch(`${this.url}/api/tenants/current/public`, { credentials: "same-origin", headers: this.#headers() });
|
|
746
|
+
const payload = (await response.json());
|
|
747
|
+
if (!payload.ok)
|
|
748
|
+
throw new FeltKitClientError(payload.error ?? { code: "INTERNAL", message: "Could not read the tenant's public settings." });
|
|
749
|
+
return payload.public;
|
|
750
|
+
}
|
|
751
|
+
/** Set the current tenant's slug, domains and branding (tenant.update); null clears one. */
|
|
752
|
+
async setTenantPublic(input) {
|
|
753
|
+
const payload = await this.#post("/api/tenants/current/public", input);
|
|
754
|
+
return payload.public;
|
|
755
|
+
}
|
|
593
756
|
async invitations() {
|
|
594
757
|
return (await this.#get("/api/tenants/current/invitations")).invitations;
|
|
595
758
|
}
|
|
@@ -1033,4 +1196,42 @@ export function waitOrWake(ms, signal, target = globalThis, doc = globalThis.doc
|
|
|
1033
1196
|
export function createClient(options) {
|
|
1034
1197
|
return new FeltKitClient(options);
|
|
1035
1198
|
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Which control frames to show. A revision is a digest, not a counter, so order comes from the state itself: the
|
|
1201
|
+
* checkpoint count and every record's sequence only grow. A frame is stale when it shows nothing newer than the
|
|
1202
|
+
* last one shown and something older; a frame that repeats the last revision changes nothing.
|
|
1203
|
+
*/
|
|
1204
|
+
export function controlRevisions() {
|
|
1205
|
+
let last = null;
|
|
1206
|
+
const marks = (state) => {
|
|
1207
|
+
const updates = new Map(state.instructions.map((i) => [i.instructionId, i.seq]));
|
|
1208
|
+
return { checkpoint: state.checkpoint, updates, terminal: state.phase === "completed" || state.phase === "stopped" };
|
|
1209
|
+
};
|
|
1210
|
+
return {
|
|
1211
|
+
accept(state) {
|
|
1212
|
+
if (last && last.revision === state.revision)
|
|
1213
|
+
return false;
|
|
1214
|
+
if (last) {
|
|
1215
|
+
const a = marks(last);
|
|
1216
|
+
const b = marks(state);
|
|
1217
|
+
let older = b.checkpoint < a.checkpoint || (a.terminal && !b.terminal);
|
|
1218
|
+
let newer = b.checkpoint > a.checkpoint || (b.terminal && !a.terminal);
|
|
1219
|
+
for (const [id, seq] of a.updates) {
|
|
1220
|
+
const next = b.updates.get(id);
|
|
1221
|
+
if (next === undefined || next < seq)
|
|
1222
|
+
older = true;
|
|
1223
|
+
else if (next > seq)
|
|
1224
|
+
newer = true;
|
|
1225
|
+
}
|
|
1226
|
+
for (const id of b.updates.keys())
|
|
1227
|
+
if (!a.updates.has(id))
|
|
1228
|
+
newer = true;
|
|
1229
|
+
if (older && !newer)
|
|
1230
|
+
return false;
|
|
1231
|
+
}
|
|
1232
|
+
last = state;
|
|
1233
|
+
return true;
|
|
1234
|
+
},
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1036
1237
|
//# sourceMappingURL=index.js.map
|