@theoremjs/web 0.3.5-next.970.g11bd0cf → 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.970.g11bd0cf",
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.970.g11bd0cf"
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";
@@ -394,6 +394,14 @@ async function* invokeAnswered(ctx, request, sessionId, { callId, pending, answe
394
394
  ...(ctx.options.onStage ? { onStage: ctx.options.onStage } : {}),
395
395
  announce: (service) => announced(ctx, request, sessionId, service),
396
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
+ }
397
405
  yield* invokeTool({
398
406
  profile: ctx.profile.id,
399
407
  ...(prepared.execution ? { execution: prepared.execution } : {}),
@@ -957,10 +965,8 @@ async function rewind(ctx, request, session) {
957
965
  return jsonResponse(200, rewound);
958
966
  }
959
967
  async function* invokeEvents(ctx, request, session, answered) {
960
- const { pending, answer } = answered;
961
- if (answer.typed)
962
- await saveCredential(ctx, session.id, answer.typed.slot, answer.typed.credential);
963
968
  const events = settleAnswered(ctx, request, session, answered);
969
+ const { pending, answer } = answered;
964
970
  yield* recorded(ctx.sessions, session.id, withAuthorizationUrls(ctx, request, session.id, events), {
965
971
  profileId: ctx.profile.id,
966
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
  /**
@@ -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,6 +71,13 @@ 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.