@theoremjs/web 0.3.5-next.967.gd19ced6 → 0.3.5-next.972.g44a2ec9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/web",
3
- "version": "0.3.5-next.967.gd19ced6",
3
+ "version": "0.3.5-next.972.g44a2ec9",
4
4
  "description": "Theorem on the web platform, with no UI framework: Web-standard server handlers that serve a profile, and the browser client that talks to them.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,6 +25,6 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^4.6.5",
28
- "@theoremjs/agents": "^0.3.5-next.967.gd19ced6"
28
+ "@theoremjs/agents": "^0.3.5-next.972.g44a2ec9"
29
29
  }
30
30
  }
package/server/handler.js CHANGED
@@ -43,7 +43,7 @@ import { authorizeToolReplay, compactHistory, defaultKernelScope, defineProfile,
43
43
  import { runConversation } from '@theoremjs/agents/conversation';
44
44
  import { caughtStatus, clientError, forClient, HTTP_NOT_FOUND, } from '@theoremjs/agents/host';
45
45
  import { clientProfileInterface, gatedToolsFromEvents, interfaceFromProfile, promotedToolIdsFromEvents, toolSnapshotFromEvents, } from '@theoremjs/agents/interface';
46
- import { answerGatedCall, resolveGateTtlMs, } from '@theoremjs/agents/kernel';
46
+ import { answerGatedCall, isSealedSource, resolveGateTtlMs, } from '@theoremjs/agents/kernel';
47
47
  import { hostInterface, theoremHostCallRequestSchema, } from "../client/host-transport.js";
48
48
  import { theoremConversationRequestSchema, theoremInvokeRequestSchema, theoremNotifyRequestSchema, theoremRewindRequestSchema, theoremSteerRequestSchema, theoremStopRequestSchema, theoremTurnRequestSchema, theoremWakeRequestSchema, } from "../client/transport.js";
49
49
  import { answerReply, conversationView, messageReply, openConversation, postedMessage, readerConversationHost, requiredOperationId, rewindConversation, statelessRefusal, waitingCalls, wakeReply, } from "./conversation.js";
@@ -262,6 +262,9 @@ function sessionCredentials(ctx, sessionId) {
262
262
  return {
263
263
  get: async (slot) => (await ctx.credentials.read(sessionId))[slot],
264
264
  set: (slot, credential) => saveCredential(ctx, sessionId, slot, credential),
265
+ delete: (slot) => ctx.credentials.mutate(sessionId, (saved) => {
266
+ delete saved[slot];
267
+ }),
265
268
  };
266
269
  }
267
270
  /** An OAuth gate given the host's sign-in URL. */
@@ -391,6 +394,14 @@ async function* invokeAnswered(ctx, request, sessionId, { callId, pending, answe
391
394
  ...(ctx.options.onStage ? { onStage: ctx.options.onStage } : {}),
392
395
  announce: (service) => announced(ctx, request, sessionId, service),
393
396
  });
397
+ if (answer.typed) {
398
+ // invariant: a sealed source keeps every key where the run cannot read it, so a key typed
399
+ // here would be saved and never sent; the person enters it where the keys are kept.
400
+ if (prepared.credentials && isSealedSource(prepared.credentials)) {
401
+ throw new TheoremError('request', `call ${callId} runs with a sealed credential source, which takes no typed secret`);
402
+ }
403
+ await saveCredential(ctx, sessionId, answer.typed.slot, answer.typed.credential);
404
+ }
394
405
  yield* invokeTool({
395
406
  profile: ctx.profile.id,
396
407
  ...(prepared.execution ? { execution: prepared.execution } : {}),
@@ -954,10 +965,8 @@ async function rewind(ctx, request, session) {
954
965
  return jsonResponse(200, rewound);
955
966
  }
956
967
  async function* invokeEvents(ctx, request, session, answered) {
957
- const { pending, answer } = answered;
958
- if (answer.typed)
959
- await saveCredential(ctx, session.id, answer.typed.slot, answer.typed.credential);
960
968
  const events = settleAnswered(ctx, request, session, answered);
969
+ const { pending, answer } = answered;
961
970
  yield* recorded(ctx.sessions, session.id, withAuthorizationUrls(ctx, request, session.id, events), {
962
971
  profileId: ctx.profile.id,
963
972
  turnInput: pending.turnInput,
@@ -7,7 +7,7 @@
7
7
  * @module
8
8
  */
9
9
  import type { NormalizedTurnRequest, StageHandler, TurnRequest, TurnWiring } from '@theoremjs/agents';
10
- import type { ToolBackgroundService, ToolCredentialSource } from '@theoremjs/agents/kernel';
10
+ import { type ToolBackgroundService, type ToolCredentialSource } from '@theoremjs/agents/kernel';
11
11
  /** The fields a handler sets on every turn, which `prepare` cannot replace. */
12
12
  export type HandlerOwned = Pick<TurnRequest, 'profile' | 'pageExecution' | 'providerState' | 'signal'>;
13
13
  /**
@@ -36,5 +36,6 @@ export declare function stagesInOrder(app: StageHandler | undefined, own: StageH
36
36
  /**
37
37
  * The application's credentials, then the session's. A credential is saved where the slot
38
38
  * already lives: a refreshed token back to the application, a sign-in at a gate to the session.
39
+ * A delete forgets the slot in both, so neither copy answers after it.
39
40
  */
40
41
  export declare function credentialsInOrder(app: ToolCredentialSource | undefined, session: ToolCredentialSource): ToolCredentialSource;
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module
8
8
  */
9
+ import { isSealedSource, } from '@theoremjs/agents/kernel';
9
10
  import { layeredToolCoordinator } from "./tool-operations.js";
10
11
  /**
11
12
  * The turn to run: `turn` through the application's `prepare`, with the handler's own fields
@@ -30,7 +31,7 @@ export async function preparedTurn(prepare, turn, handler) {
30
31
  ...(execution ? { execution } : {}),
31
32
  ...(background ? { background } : {}),
32
33
  ...(lateResults ? { lateResults } : {}),
33
- credentials: credentialsInOrder(app.credentials, handler.credentials),
34
+ credentials: turnCredentials(app.credentials, handler.credentials),
34
35
  ...(onStage ? { onStage } : {}),
35
36
  };
36
37
  }
@@ -70,9 +71,17 @@ export function stagesInOrder(app, own) {
70
71
  return app ?? own;
71
72
  return async (ctx) => (await app(ctx)) ?? (await own(ctx));
72
73
  }
74
+ /**
75
+ * A sealed application source stands alone: its keys never reach this process, so the session
76
+ * holds none beside it. Any other source goes before the session's.
77
+ */
78
+ function turnCredentials(app, session) {
79
+ return app && isSealedSource(app) ? app : credentialsInOrder(app, session);
80
+ }
73
81
  /**
74
82
  * The application's credentials, then the session's. A credential is saved where the slot
75
83
  * already lives: a refreshed token back to the application, a sign-in at a gate to the session.
84
+ * A delete forgets the slot in both, so neither copy answers after it.
76
85
  */
77
86
  export function credentialsInOrder(app, session) {
78
87
  if (!app)
@@ -82,6 +91,10 @@ export function credentialsInOrder(app, session) {
82
91
  return {
83
92
  get: async (slot) => (await app.get(slot)) ?? (await session.get(slot)),
84
93
  set: async (slot, credential) => (await app.get(slot)) ? await app.set(slot, credential) : await session.set(slot, credential),
94
+ delete: async (slot) => {
95
+ await app.delete(slot);
96
+ await session.delete(slot);
97
+ },
85
98
  ...(secrets.clientSecret
86
99
  ? { clientSecret: async (clientId) => await secrets.clientSecret?.(clientId) }
87
100
  : {}),