@datalayer/agent-runtimes 1.5.111 → 1.5.115

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.
@@ -396,6 +396,8 @@ function parsePap(data) {
396
396
  company: {
397
397
  enabled: flag(company.enabled, false),
398
398
  signedOut: flag(company.signed_out, true),
399
+ signInDisabled: flag(company.sign_in_disabled, false),
400
+ publishSkills: flag(company.publish_skills, false),
399
401
  interfaces: enumsOf(company.interfaces, PAP_INTERFACES, PAP_DEFAULT_INTERFACES),
400
402
  scopes: records(company.scopes).map(parsePapCompanyScope),
401
403
  excludedTasks: records(company.excluded_tasks).map(task => ({
@@ -506,6 +508,8 @@ function dumpPap(pap) {
506
508
  .part('company', new Writer()
507
509
  .value('enabled', pap.company.enabled, false)
508
510
  .value('signed_out', pap.company.signedOut, true)
511
+ .value('sign_in_disabled', pap.company.signInDisabled, false)
512
+ .value('publish_skills', pap.company.publishSkills, false)
509
513
  .list('interfaces', pap.company.interfaces, [...PAP_DEFAULT_INTERFACES])
510
514
  .list('scopes', pap.company.scopes.map(dumpPapCompanyScope))
511
515
  .list('excluded_tasks', pap.company.excludedTasks.map(dumpPapExcludedTask))
@@ -6,6 +6,8 @@ export type DatalayerVisitors = {
6
6
  app: string;
7
7
  /** ai-inference, which mints the visitor's token. */
8
8
  inferenceUrl: string;
9
+ /** The catalogue Battle the token is played for, when it is (B4-01). */
10
+ battle?: string;
9
11
  };
10
12
  /** A visitor's id: what ai-inference accepts (8 to 64 letters, digits or dashes). */
11
13
  export declare function isVisitorId(value: string | null | undefined): value is string;
@@ -18,13 +20,30 @@ export type VisitorToken = {
18
20
  /** Epoch milliseconds: the token's own lifetime from now. */
19
21
  renewAt: number;
20
22
  };
21
- /** The body ai-inference is asked with. */
22
- export declare function visitorTokenRequest(app: string, visitor: string): {
23
- app: string;
23
+ /** The body ai-inference is asked with: the application, the visitor once there is one, the Battle when it is played for one. */
24
+ export declare function visitorTokenRequest(app: string, visitor: string, battle?: string): {
25
+ app?: string;
24
26
  visitor?: string;
27
+ battle?: string;
25
28
  };
26
- /** Mint a visitor's token for an application; throws with ai-inference's sentence. */
27
- export declare function fetchVisitorToken(inferenceUrl: string, app: string, visitor?: string, fetcher?: typeof fetch): Promise<VisitorToken>;
29
+ /** Mint a visitor's token for an application — played for a Battle when `battle` names one; throws with ai-inference's sentence. */
30
+ export declare function fetchVisitorToken(inferenceUrl: string, app: string, visitor?: string, fetcher?: typeof fetch, battle?: string): Promise<VisitorToken>;
31
+ /** A Battle's token for the page's players: its own budget at ai-inference, for one play. */
32
+ export type BattleToken = {
33
+ token: string;
34
+ visitor: string;
35
+ /** Epoch milliseconds: the token's own lifetime from now. */
36
+ expiresAt: number;
37
+ /** How long it was signed for, as the token declares. */
38
+ lifetimeMs: number;
39
+ };
40
+ /**
41
+ * Mint the token one play of a catalogue Battle is played with, by the
42
+ * visitor this tab keeps (B4-01): the players in the page call their models
43
+ * with it, its calls counted against the play's budget. Never renewed: a play
44
+ * is minutes, and the next play mints its own.
45
+ */
46
+ export declare function fetchBattleToken(inferenceUrl: string, battle: string, visitor?: string, fetcher?: typeof fetch): Promise<BattleToken>;
28
47
  /**
29
48
  * The visitor's token for an application while `visitors` is set: minted at
30
49
  * once and again before it runs out. `error` says why none could be had.
@@ -14,9 +14,16 @@
14
14
  * visitor is on the servers (turns a day, a session's minutes, a rate and a
15
15
  * ceiling for the day), not the life of a key.
16
16
  *
17
+ * A token may also name the catalogue Battle it is played for (B4-01): its
18
+ * model calls then count against that play's own budget at ai-inference,
19
+ * instead of the visitor's rate, and the runtime that plays a member of the
20
+ * Battle's scene reads the Battle from it (`fetchBattleToken`, and
21
+ * `DatalayerVisitors.battle` for the members).
22
+ *
17
23
  * @module apps/apps/visitorToken
18
24
  */
19
25
  import { useEffect, useState } from 'react';
26
+ import { tokenLifetimeMs } from '../../runtimes/browser/anonymousToken.js';
20
27
  /** The id this tab keeps for its visitor. */
21
28
  const VISITOR_KEY = 'datalayer-loop-visitor';
22
29
  /** Minted again this long before the token runs out. */
@@ -43,17 +50,21 @@ function keepVisitorId(visitor) {
43
50
  // A tab that keeps nothing is a new visitor at each token.
44
51
  }
45
52
  }
46
- /** The body ai-inference is asked with. */
47
- export function visitorTokenRequest(app, visitor) {
48
- return isVisitorId(visitor) ? { app, visitor } : { app };
53
+ /** The body ai-inference is asked with: the application, the visitor once there is one, the Battle when it is played for one. */
54
+ export function visitorTokenRequest(app, visitor, battle = '') {
55
+ return {
56
+ ...(app ? { app } : {}),
57
+ ...(isVisitorId(visitor) ? { visitor } : {}),
58
+ ...(battle ? { battle } : {}),
59
+ };
49
60
  }
50
- /** Mint a visitor's token for an application; throws with ai-inference's sentence. */
51
- export async function fetchVisitorToken(inferenceUrl, app, visitor = keptVisitorId(), fetcher = fetch) {
61
+ /** Ask ai-inference for a token; throws with its sentence. The visitor it names is kept for the next one. */
62
+ async function mintVisitorToken(inferenceUrl, request, fetcher) {
52
63
  const base = inferenceUrl.replace(/\/+$/, '');
53
64
  const response = await fetcher(`${base}/api/ai-inference/v1/anonymous/token`, {
54
65
  method: 'POST',
55
66
  headers: { 'Content-Type': 'application/json' },
56
- body: JSON.stringify(visitorTokenRequest(app, visitor)),
67
+ body: JSON.stringify(request),
57
68
  });
58
69
  const body = (await response.json().catch(() => ({})));
59
70
  if (!response.ok || !body.token) {
@@ -63,6 +74,15 @@ export async function fetchVisitorToken(inferenceUrl, app, visitor = keptVisitor
63
74
  if (isVisitorId(body.visitor)) {
64
75
  keepVisitorId(body.visitor);
65
76
  }
77
+ return {
78
+ token: body.token,
79
+ visitor: body.visitor,
80
+ expires_in: body.expires_in,
81
+ };
82
+ }
83
+ /** Mint a visitor's token for an application — played for a Battle when `battle` names one; throws with ai-inference's sentence. */
84
+ export async function fetchVisitorToken(inferenceUrl, app, visitor = keptVisitorId(), fetcher = fetch, battle = '') {
85
+ const body = await mintVisitorToken(inferenceUrl, visitorTokenRequest(app, visitor, battle), fetcher);
66
86
  const lifetimeMs = Math.max(60_000, (body.expires_in ?? 300) * 1000);
67
87
  return {
68
88
  token: body.token,
@@ -70,6 +90,25 @@ export async function fetchVisitorToken(inferenceUrl, app, visitor = keptVisitor
70
90
  renewAt: Date.now() + lifetimeMs - MARGIN_MS,
71
91
  };
72
92
  }
93
+ /**
94
+ * Mint the token one play of a catalogue Battle is played with, by the
95
+ * visitor this tab keeps (B4-01): the players in the page call their models
96
+ * with it, its calls counted against the play's budget. Never renewed: a play
97
+ * is minutes, and the next play mints its own.
98
+ */
99
+ export async function fetchBattleToken(inferenceUrl, battle, visitor = keptVisitorId(), fetcher = fetch) {
100
+ if (!battle) {
101
+ throw new Error('A Battle token is minted for a Battle.');
102
+ }
103
+ const body = await mintVisitorToken(inferenceUrl, visitorTokenRequest('', visitor, battle), fetcher);
104
+ const lifetimeMs = tokenLifetimeMs(body.token, body.expires_in);
105
+ return {
106
+ token: body.token,
107
+ visitor: body.visitor ?? visitor,
108
+ expiresAt: Date.now() + lifetimeMs,
109
+ lifetimeMs,
110
+ };
111
+ }
73
112
  /**
74
113
  * The visitor's token for an application while `visitors` is set: minted at
75
114
  * once and again before it runs out. `error` says why none could be had.
@@ -78,6 +117,7 @@ export function useVisitorToken(visitors) {
78
117
  const [state, setState] = useState({});
79
118
  const app = visitors?.app;
80
119
  const inferenceUrl = visitors?.inferenceUrl;
120
+ const battle = visitors?.battle ?? '';
81
121
  useEffect(() => {
82
122
  if (!app || !inferenceUrl) {
83
123
  setState({});
@@ -86,7 +126,7 @@ export function useVisitorToken(visitors) {
86
126
  let cancelled = false;
87
127
  let timer;
88
128
  const mint = () => {
89
- fetchVisitorToken(inferenceUrl, app)
129
+ fetchVisitorToken(inferenceUrl, app, keptVisitorId(), fetch, battle)
90
130
  .then(minted => {
91
131
  if (cancelled) {
92
132
  return;
@@ -109,7 +149,7 @@ export function useVisitorToken(visitors) {
109
149
  clearTimeout(timer);
110
150
  }
111
151
  };
112
- }, [app, inferenceUrl]);
152
+ }, [app, inferenceUrl, battle]);
113
153
  return state;
114
154
  }
115
155
  /** What a token for an application at its address names: `at:<slug>`. */
@@ -73,5 +73,11 @@ export declare function secondsLeft(spec: BattleSpec, record: BattleRecord, now:
73
73
  export declare function verdictOf(spec: BattleSpec, record: BattleRecord): BattleVerdict;
74
74
  /** A record at the start of a Battle: every contestant started, nothing done. */
75
75
  export declare function startRecord(spec: BattleSpec, startedAt: number): BattleRecord;
76
- /** Whether the Battle's own rule ends it now: a race once someone is done, a game once the arena says so. */
76
+ /**
77
+ * Whether the Battle's own rule ends it now: a race once every contestant is
78
+ * done (the user, 7 November 2026: the slowest may be the one whose tests
79
+ * pass, so nobody is stopped on the first answer; the first done still
80
+ * ranks first), a game once the arena says so, a challenge once everyone is
81
+ * done. The clock ends any of them.
82
+ */
77
83
  export declare function ruleEnds(spec: BattleSpec, record: BattleRecord, arenaOver?: boolean): boolean;
@@ -109,11 +109,17 @@ export function startRecord(spec, startedAt) {
109
109
  moves: [],
110
110
  };
111
111
  }
112
- /** Whether the Battle's own rule ends it now: a race once someone is done, a game once the arena says so. */
112
+ /**
113
+ * Whether the Battle's own rule ends it now: a race once every contestant is
114
+ * done (the user, 7 November 2026: the slowest may be the one whose tests
115
+ * pass, so nobody is stopped on the first answer; the first done still
116
+ * ranks first), a game once the arena says so, a challenge once everyone is
117
+ * done. The clock ends any of them.
118
+ */
113
119
  export function ruleEnds(spec, record, arenaOver = false) {
114
120
  switch (spec.referee.decidesBy) {
115
121
  case 'first_done':
116
- return record.contestants.some(contestant => contestant.doneAt !== undefined);
122
+ return record.contestants.every(contestant => contestant.doneAt !== undefined);
117
123
  case 'score':
118
124
  return arenaOver;
119
125
  case 'measure':
@@ -39,7 +39,7 @@ const sampleCompany = (domain) => ({
39
39
  ],
40
40
  extensions: { operations: { version: '1' } },
41
41
  }),
42
- // Direct and Device are what the issuer's grants say (draft 0.3 §3.2).
42
+ // Direct and Device are what the issuer's grants say (0.3 as published §3.2).
43
43
  oauthMetadata: parseOAuthServerMetadata({
44
44
  issuer: `https://auth.${domain}`,
45
45
  token_endpoint: `https://auth.${domain}/token`,
@@ -80,6 +80,6 @@ const PapCompanyDiscoveryView = () => {
80
80
  setError(cause instanceof Error ? cause.message : String(cause));
81
81
  }
82
82
  };
83
- return (_jsxs(PapExamplePage, { eyebrow: "PAP \u00B7 Company discovery", title: "Discover capabilities, not credentials", description: "The PAP parser validates the discovery document and the issuer's metadata (draft 0.3); Agent Runtimes then projects them into a model-safe summary: the sign-ins the issuer's grants offer, the company's own scopes with their hints, and the domains its issuer protects. Change the sample domain to see issuer and discovery binding move together.", children: [_jsxs(Box, { display: "flex", flexDirection: "column", gap: 3, p: 3, border: "1px solid", borderColor: "border.default", borderRadius: 2, bg: "canvas.default", children: [_jsx(Text, { as: "label", sx: { fontWeight: 600 }, children: "Company DNS domain" }), _jsxs(Box, { display: "flex", gap: 2, children: [_jsx(TextInput, { block: true, value: domain, "aria-label": "Company DNS domain", onChange: event => setDomain(event.target.value) }), _jsx(Button, { variant: "primary", onClick: () => void inspect(), children: "Validate sample" })] }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "The sample uses an injected Reactor-compatible transport. Production replaces it with DNS-pinned HTTPS discovery." }), error ? _jsx(Text, { sx: { color: 'danger.fg' }, children: error }) : null] }), summary ? (_jsx(PapResult, { title: "Safe company summary", value: summary })) : null] }));
83
+ return (_jsxs(PapExamplePage, { eyebrow: "PAP \u00B7 Company discovery", title: "Discover capabilities, not credentials", description: "The PAP parser validates the discovery document and the issuer's metadata (0.3 as published); Agent Runtimes then projects them into a model-safe summary: the sign-ins the issuer's grants offer, the company's own scopes with their hints, and the domains its issuer protects. Change the sample domain to see issuer and discovery binding move together.", children: [_jsxs(Box, { display: "flex", flexDirection: "column", gap: 3, p: 3, border: "1px solid", borderColor: "border.default", borderRadius: 2, bg: "canvas.default", children: [_jsx(Text, { as: "label", sx: { fontWeight: 600 }, children: "Company DNS domain" }), _jsxs(Box, { display: "flex", gap: 2, children: [_jsx(TextInput, { block: true, value: domain, "aria-label": "Company DNS domain", onChange: event => setDomain(event.target.value) }), _jsx(Button, { variant: "primary", onClick: () => void inspect(), children: "Validate sample" })] }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "The sample uses an injected Reactor-compatible transport. Production replaces it with DNS-pinned HTTPS discovery." }), error ? _jsx(Text, { sx: { color: 'danger.fg' }, children: error }) : null] }), summary ? (_jsx(PapResult, { title: "Safe company summary", value: summary })) : null] }));
84
84
  };
85
85
  export default PapCompanyDiscoveryView;
@@ -28,7 +28,7 @@ const STEPS = [
28
28
  channel: 'Discovery',
29
29
  messages: conversationStart,
30
30
  facts: [
31
- { label: 'Publishes', value: 'poppy.json · draft 0.3' },
31
+ { label: 'Publishes', value: 'poppy.json · 0.3 as published' },
32
32
  { label: 'Returns', value: 'Company conversation agent' },
33
33
  { label: 'Sign-in', value: "Northstar's own page" },
34
34
  ],
@@ -256,7 +256,7 @@ const runJourney = async () => {
256
256
  ],
257
257
  },
258
258
  });
259
- // Direct Sign-In is what the issuer's grants offer (draft 0.3 §3.2).
259
+ // Direct Sign-In is what the issuer's grants offer (0.3 as published §3.2).
260
260
  parseOAuthServerMetadata({
261
261
  issuer: 'https://auth.northstar.example',
262
262
  token_endpoint: 'https://auth.northstar.example/oauth/token',
@@ -52,7 +52,7 @@ const PapSessionJwtView = () => {
52
52
  urlBoundWithoutQueryOrFragment: claims.htu === 'https://api.company.example/orders',
53
53
  accessTokenBound: typeof claims.ath === 'string',
54
54
  namesItsSession: claims.sid === request.sid,
55
- carriesItsDelegation: typeof header.pap_dlg === 'string',
55
+ carriesItsDelegation: typeof header.poppy_dlg === 'string',
56
56
  oneKeyPerUserId: header.kid !== part(other.reveal(), 0).kid,
57
57
  jwtRedactedByDefault: first.toJSON() === '[REDACTED]',
58
58
  jwtWithheldFromUiState: true,
@@ -21,7 +21,7 @@ const PapSessionLifecycleView = () => {
21
21
  calls += 1;
22
22
  jwts.push(new Headers(init?.headers).get('Poppy-Session') ?? '');
23
23
  return calls === 1
24
- ? new Response(JSON.stringify({ error: 'invalid_session' }), {
24
+ ? new Response(JSON.stringify({ error: 'session_ended' }), {
25
25
  status: 400,
26
26
  headers: { 'content-type': 'application/json' },
27
27
  })
@@ -81,6 +81,6 @@ const PapSessionLifecycleView = () => {
81
81
  reactor.stop();
82
82
  }
83
83
  };
84
- return (_jsxs(PapExamplePage, { eyebrow: "PAP \u00B7 Session", title: "Start and restart a Session without giving credentials to the agent", description: "This Reactor view drives the real PAP SessionClient and SessionFetchClient (draft 0.3) against a deterministic company transport. A Session is local: a random sid, and no request. Every request carries a fresh Poppy-Session JWT signed with a delegated key. Answered invalid_session, it starts again once, with a new sid and the same User ID. Only lifecycle evidence enters React state.", children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 3, p: 3, border: "1px solid", borderColor: "border.default", borderRadius: 2, bg: "canvas.default", children: [_jsx(Text, { sx: { color: 'fg.muted' }, children: "Exercise start, the Session header and a restart entirely inside this host." }), _jsx(Button, { variant: "primary", onClick: () => void runLifecycle(), children: "Run lifecycle" })] }), error ? _jsx(Text, { sx: { color: 'danger.fg' }, children: error }) : null, summary ? (_jsx(PapResult, { title: "Safe Session evidence", value: summary })) : null] }));
84
+ return (_jsxs(PapExamplePage, { eyebrow: "PAP \u00B7 Session", title: "Start and restart a Session without giving credentials to the agent", description: "This Reactor view drives the real PAP SessionClient and SessionFetchClient (0.3 as published) against a deterministic company transport. A Session is local: a random sid, and no request. Every request carries a fresh Poppy-Session JWT signed with a delegated key. Answered invalid_session, it starts again once, with a new sid and the same User ID. Only lifecycle evidence enters React state.", children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 3, p: 3, border: "1px solid", borderColor: "border.default", borderRadius: 2, bg: "canvas.default", children: [_jsx(Text, { sx: { color: 'fg.muted' }, children: "Exercise start, the Session header and a restart entirely inside this host." }), _jsx(Button, { variant: "primary", onClick: () => void runLifecycle(), children: "Run lifecycle" })] }), error ? _jsx(Text, { sx: { color: 'danger.fg' }, children: error }) : null, summary ? (_jsx(PapResult, { title: "Safe Session evidence", value: summary })) : null] }));
85
85
  };
86
86
  export default PapSessionLifecycleView;
@@ -732,6 +732,151 @@
732
732
  }
733
733
  }
734
734
  ]
735
+ },
736
+ {
737
+ "title": "Manzanita asks for Ada",
738
+ "channel": "Company-first Direct Conversation",
739
+ "summary": "Manzanita's agent asks for the person with a user_requested event (a returns specialist wants to talk about the damaged jacket). Ada accepts: Atlas opens a Direct Conversation under the parent naming the event, with no message of its own, and Manzanita speaks first. Accepted again, the same conversation comes back (§8.10).",
740
+ "chat": [
741
+ {
742
+ "speaker": "manzanita",
743
+ "kind": "message",
744
+ "text": "A returns specialist would like to talk with you about the damaged jacket."
745
+ },
746
+ {
747
+ "speaker": "user",
748
+ "kind": "message",
749
+ "text": "Yes, put me through."
750
+ },
751
+ {
752
+ "speaker": "manzanita",
753
+ "kind": "message",
754
+ "text": "Hello Ada, this is the returns desk. What happened to the jacket?"
755
+ }
756
+ ],
757
+ "views": {
758
+ "atlas": [
759
+ {
760
+ "label": "Company",
761
+ "value": "Manzanita Outfitters · discovery verified"
762
+ },
763
+ {
764
+ "label": "Session",
765
+ "value": "signed out · a Session JWT on every request"
766
+ },
767
+ {
768
+ "label": "Invitation",
769
+ "value": "user_requested evt_7 · accepted by Ada, never by the model"
770
+ },
771
+ {
772
+ "label": "Model sees",
773
+ "value": "Summaries and statuses, never a credential"
774
+ }
775
+ ],
776
+ "manzanita": [
777
+ {
778
+ "label": "Verified client",
779
+ "value": "atlas.example/agent.json"
780
+ },
781
+ {
782
+ "label": "Conversation",
783
+ "value": "idle · agent · 7 events"
784
+ },
785
+ {
786
+ "label": "Direct conversation",
787
+ "value": "cnv_3 · opened by the company's first message"
788
+ },
789
+ {
790
+ "label": "Owner",
791
+ "value": "client_id + User ID (§8.2)"
792
+ }
793
+ ]
794
+ },
795
+ "sequence": [
796
+ {
797
+ "kind": "http",
798
+ "from": "atlas",
799
+ "to": "manzanita",
800
+ "method": "POST",
801
+ "url": "https://manzanita.example/poppy/conversations?wait=0",
802
+ "status": 201,
803
+ "request": {
804
+ "headers": {
805
+ "content-type": "application/json",
806
+ "accept": "*/*",
807
+ "poppy-session": "‹Session JWT›"
808
+ },
809
+ "body": {
810
+ "parent_conversation_id": "cnv_1",
811
+ "user_requested_event_id": "evt_7"
812
+ }
813
+ },
814
+ "response": {
815
+ "headers": {
816
+ "content-type": "application/json"
817
+ },
818
+ "body": {
819
+ "conversation_id": "cnv_3",
820
+ "events": [
821
+ {
822
+ "id": "evt_1",
823
+ "created_at": "2026-11-07T09:05:00Z",
824
+ "type": "message",
825
+ "message": {
826
+ "id": "msg_9",
827
+ "author": {
828
+ "type": "agent",
829
+ "name": "Manzanita Outfitters"
830
+ },
831
+ "role": "company",
832
+ "text": "Hello Ada, this is the returns desk. What happened to the jacket?"
833
+ }
834
+ },
835
+ {
836
+ "id": "evt_2",
837
+ "created_at": "2026-11-07T09:05:00Z",
838
+ "type": "state",
839
+ "status": "idle",
840
+ "responder": "agent"
841
+ }
842
+ ],
843
+ "cursor": "evt_2",
844
+ "has_more": false,
845
+ "status": "idle",
846
+ "responder": "agent"
847
+ }
848
+ }
849
+ },
850
+ {
851
+ "kind": "http",
852
+ "from": "atlas",
853
+ "to": "manzanita",
854
+ "method": "POST",
855
+ "url": "https://manzanita.example/poppy/conversations?wait=0",
856
+ "status": 201,
857
+ "request": {
858
+ "headers": {
859
+ "content-type": "application/json",
860
+ "accept": "*/*",
861
+ "poppy-session": "‹Session JWT›"
862
+ },
863
+ "body": {
864
+ "parent_conversation_id": "cnv_1",
865
+ "user_requested_event_id": "evt_7"
866
+ }
867
+ },
868
+ "response": {
869
+ "headers": {
870
+ "content-type": "application/json"
871
+ },
872
+ "body": {
873
+ "conversation_id": "cnv_3",
874
+ "status": "idle",
875
+ "responder": "agent"
876
+ }
877
+ }
878
+ }
879
+ ]
735
880
  }
736
881
  ]
737
882
  }