agentfootprint 9.29.0 → 9.30.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/adapters/google/aiPlatform.js +23 -1
- package/dist/adapters/google/aiPlatform.js.map +1 -1
- package/dist/adapters/hosting/googleAgentEngine.js +163 -58
- package/dist/adapters/hosting/googleAgentEngine.js.map +1 -1
- package/dist/adapters/identity/google.js +18 -4
- package/dist/adapters/identity/google.js.map +1 -1
- package/dist/adapters/llm/GeminiProvider.js +8 -3
- package/dist/adapters/llm/GeminiProvider.js.map +1 -1
- package/dist/adapters/memory/memoryBank.js +234 -14
- package/dist/adapters/memory/memoryBank.js.map +1 -1
- package/dist/esm/adapters/google/aiPlatform.d.ts +44 -0
- package/dist/esm/adapters/google/aiPlatform.js +23 -1
- package/dist/esm/adapters/google/aiPlatform.js.map +1 -1
- package/dist/esm/adapters/hosting/googleAgentEngine.d.ts +87 -15
- package/dist/esm/adapters/hosting/googleAgentEngine.js +162 -57
- package/dist/esm/adapters/hosting/googleAgentEngine.js.map +1 -1
- package/dist/esm/adapters/identity/google.d.ts +18 -4
- package/dist/esm/adapters/identity/google.js +18 -4
- package/dist/esm/adapters/identity/google.js.map +1 -1
- package/dist/esm/adapters/llm/GeminiProvider.d.ts +8 -3
- package/dist/esm/adapters/llm/GeminiProvider.js +8 -3
- package/dist/esm/adapters/llm/GeminiProvider.js.map +1 -1
- package/dist/esm/adapters/memory/memoryBank.d.ts +25 -10
- package/dist/esm/adapters/memory/memoryBank.js +233 -13
- package/dist/esm/adapters/memory/memoryBank.js.map +1 -1
- package/dist/esm/hosting-providers.d.ts +4 -2
- package/dist/esm/hosting-providers.js +4 -2
- package/dist/esm/hosting-providers.js.map +1 -1
- package/dist/esm/memory-providers.d.ts +1 -1
- package/dist/esm/memory-providers.js +4 -2
- package/dist/esm/memory-providers.js.map +1 -1
- package/dist/hosting-providers.js +5 -2
- package/dist/hosting-providers.js.map +1 -1
- package/dist/memory-providers.js +5 -2
- package/dist/memory-providers.js.map +1 -1
- package/dist/types/adapters/google/aiPlatform.d.ts +44 -0
- package/dist/types/adapters/google/aiPlatform.d.ts.map +1 -1
- package/dist/types/adapters/hosting/googleAgentEngine.d.ts +87 -15
- package/dist/types/adapters/hosting/googleAgentEngine.d.ts.map +1 -1
- package/dist/types/adapters/identity/google.d.ts +18 -4
- package/dist/types/adapters/identity/google.d.ts.map +1 -1
- package/dist/types/adapters/llm/GeminiProvider.d.ts +8 -3
- package/dist/types/adapters/llm/GeminiProvider.d.ts.map +1 -1
- package/dist/types/adapters/memory/memoryBank.d.ts +25 -10
- package/dist/types/adapters/memory/memoryBank.d.ts.map +1 -1
- package/dist/types/hosting-providers.d.ts +4 -2
- package/dist/types/hosting-providers.d.ts.map +1 -1
- package/dist/types/memory-providers.d.ts +1 -1
- package/dist/types/memory-providers.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -14,23 +14,53 @@
|
|
|
14
14
|
* was designed under; where the product name and the API disagree, the API is
|
|
15
15
|
* the one that has not moved.
|
|
16
16
|
*
|
|
17
|
-
* ── The fit, and
|
|
17
|
+
* ── The fit, and the one thing it cost ──────────────────────────────────────
|
|
18
18
|
* `Session.sessionState` is an arbitrary JSON `Struct`. A `CheckpointEnvelope`
|
|
19
19
|
* is arbitrary JSON. So the envelope goes in whole, under one key, and comes
|
|
20
|
-
* back whole — no event log to fold, no blob encoding to get wrong
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* event blob comes back as somebody else's `toString()`.
|
|
20
|
+
* back whole — no event log to fold, no blob encoding to get wrong. What it
|
|
21
|
+
* cost is the WRITE VERB, and that took a field trial to learn: state goes in
|
|
22
|
+
* through an appended EVENT, never through a patch. See fact 2b below.
|
|
24
23
|
*
|
|
25
|
-
* ── The
|
|
24
|
+
* ── The five facts that shaped the code ─────────────────────────────────────
|
|
26
25
|
* 1. **`sessions.create` takes a caller-supplied `sessionId`.** So our session
|
|
27
26
|
* id IS the resource id and `hydrate` is one `get` by name. No mapping
|
|
28
27
|
* table, no listing to find a conversation.
|
|
29
28
|
* 2. **`create` and `delete` answer a long-running Operation; `get` and
|
|
30
|
-
* `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
29
|
+
* `appendEvent` answer directly.** Every operation-shaped write here waits
|
|
30
|
+
* for `done` before it returns — a `persist` that returned early would make
|
|
31
|
+
* the very next `hydrate` a race whose failure mode is "no conversation",
|
|
32
|
+
* which nobody can tell from a new user.
|
|
33
|
+
*
|
|
34
|
+
* 2b. **`sessionState` CANNOT be patched. This one is field truth, and it cost
|
|
35
|
+
* a release.** 9.29.0 wrote the steady state as
|
|
36
|
+
* `sessions.patch({ updateMask: 'sessionState,ttl' })`, which every
|
|
37
|
+
* injected-client test accepted because a double will patch anything. An
|
|
38
|
+
* independent field trial ran it against the live service (2026-08-14) and
|
|
39
|
+
* found that turn one stored and **every later turn failed**:
|
|
40
|
+
*
|
|
41
|
+
* HTTP 400 — "Can't update the session state for session …, you can only
|
|
42
|
+
* update it by appending an event."
|
|
43
|
+
*
|
|
44
|
+
* A store that keeps the first turn of a conversation and refuses the
|
|
45
|
+
* second is not a session store, so the verb changed rather than the
|
|
46
|
+
* documentation: `persist` now appends a `SessionEvent` whose
|
|
47
|
+
* `actions.stateDelta` carries the envelope, which the same trial verified
|
|
48
|
+
* end to end (append accepted, `GET` returned the new state).
|
|
49
|
+
*
|
|
50
|
+
* Two consequences worth saying out loud, because they are the difference
|
|
51
|
+
* between this fix and a plausible-looking one:
|
|
52
|
+
*
|
|
53
|
+
* • **A state delta MERGES by top-level key.** This store writes exactly
|
|
54
|
+
* one key — {@link SESSION_STATE_KEY} — so "merge the delta" and
|
|
55
|
+
* "replace our key" are the same outcome for us, and another guest's
|
|
56
|
+
* keys under the same session are left alone either way.
|
|
57
|
+
* • **A conversation now has an event log behind it**, one event per
|
|
58
|
+
* persisted turn, because that is the only writing surface the service
|
|
59
|
+
* offers. Nothing here READS that log — `hydrate` still reads the one
|
|
60
|
+
* envelope out of `sessionState` — so the log is the service's audit
|
|
61
|
+
* trail of our writes and never a second copy of the truth. Sessions
|
|
62
|
+
* are per-conversation and events are small; if that growth matters to
|
|
63
|
+
* you, `forget()` deletes the session and its events together.
|
|
34
64
|
* 3. **`Session.userId` is required and immutable.** Our port's
|
|
35
65
|
* `persist(sessionId, envelope)` carries no user, so one has to be
|
|
36
66
|
* resolved — see {@link AgentEngineSessionsOptions.userId}. Immutable
|
|
@@ -52,8 +82,15 @@
|
|
|
52
82
|
* before handing a session id down here. This adapter is a STORE. Nothing
|
|
53
83
|
* that only stores can tell an impostor from an owner.
|
|
54
84
|
* 4. **`ttl` is input-only with a 24-hour floor**, and `expireTime` always
|
|
55
|
-
* comes back.
|
|
56
|
-
*
|
|
85
|
+
* comes back. An hour-long TTL is not available at any price.
|
|
86
|
+
*
|
|
87
|
+
* **Sliding expiry is NOT claimed here**, and that changed with fact 2b. A
|
|
88
|
+
* `ttl` is sent on `create`, where the service takes it; later turns append
|
|
89
|
+
* an event, and whether an appended event renews the expiry is a service
|
|
90
|
+
* behaviour nothing in this repository has measured. Rather than send an
|
|
91
|
+
* unverified second call per turn to "refresh" it — a write whose only
|
|
92
|
+
* evidence would be that it did not error — the adapter sends the ttl once
|
|
93
|
+
* and says so. See {@link AgentEngineSessionsOptions.ttl}.
|
|
57
94
|
*
|
|
58
95
|
* ── The laws it inherits rather than re-implements ──────────────────────────
|
|
59
96
|
* `checkEnvelope` runs on the way OUT and on the way IN, so an envelope whose
|
|
@@ -108,8 +145,23 @@ export interface AgentEngineSessionsOptions extends AiPlatformConnection {
|
|
|
108
145
|
*
|
|
109
146
|
* Omit and no `ttl` is sent, which leaves the service's own default
|
|
110
147
|
* expiry in charge.
|
|
148
|
+
*
|
|
149
|
+
* **Sent on CREATE only.** Later turns append an event (see the module
|
|
150
|
+
* header, fact 2b), and whether an appended event renews the expiry is not
|
|
151
|
+
* something this repository has measured — so a long conversation may still
|
|
152
|
+
* expire on the clock started by its first turn. If you need a conversation
|
|
153
|
+
* to outlive that, set a `ttl` long enough at creation.
|
|
111
154
|
*/
|
|
112
155
|
readonly ttl?: string;
|
|
156
|
+
/**
|
|
157
|
+
* The `author` recorded on every event this store appends. Default
|
|
158
|
+
* {@link SESSION_EVENT_AUTHOR}.
|
|
159
|
+
*
|
|
160
|
+
* The service requires one and treats it as free text; it is who the console
|
|
161
|
+
* shows as having written the turn. This is not the conversation's owner —
|
|
162
|
+
* that is `userId`, which is pinned at create and immutable.
|
|
163
|
+
*/
|
|
164
|
+
readonly eventAuthor?: string;
|
|
113
165
|
/**
|
|
114
166
|
* How long a write waits for its long-running operation before refusing.
|
|
115
167
|
* Default {@link DEFAULT_OPERATION_TIMEOUT_MS} (30s).
|
|
@@ -122,6 +174,15 @@ export interface AgentEngineSessionsOptions extends AiPlatformConnection {
|
|
|
122
174
|
}
|
|
123
175
|
/** What a conversation that named nobody is stored under. */
|
|
124
176
|
export declare const DEFAULT_USER_ID = "agentfootprint-anonymous";
|
|
177
|
+
/**
|
|
178
|
+
* The `author` on every event this store appends, unless
|
|
179
|
+
* {@link AgentEngineSessionsOptions.eventAuthor} names another.
|
|
180
|
+
*
|
|
181
|
+
* The service requires the field and treats it as free text. This name says
|
|
182
|
+
* which library wrote the turn, which is the useful thing to see in the console
|
|
183
|
+
* beside somebody else's agent writing to the same engine.
|
|
184
|
+
*/
|
|
185
|
+
export declare const SESSION_EVENT_AUTHOR = "agentfootprint";
|
|
125
186
|
/**
|
|
126
187
|
* A session store in Vertex AI's session service.
|
|
127
188
|
*
|
|
@@ -149,9 +210,20 @@ export interface AgentEngineSessions extends SessionLifecycle {
|
|
|
149
210
|
* Conversations in Vertex AI's session service — the store that survives a
|
|
150
211
|
* fleet, not just a restart.
|
|
151
212
|
*
|
|
152
|
-
* **Status:
|
|
153
|
-
*
|
|
154
|
-
*
|
|
213
|
+
* **Status: field-validated except the write verb, which is field-CORRECTED.**
|
|
214
|
+
* An independent trial ran this adapter against a live Agent Runtime engine
|
|
215
|
+
* (2026-08-14) and everything below answered a real request from Google:
|
|
216
|
+
* creating first-turn sessions from real envelopes, hydrating them through a
|
|
217
|
+
* fresh instance, owners preserved, paged `listByUser` filtering, `ownerOf`,
|
|
218
|
+
* an unknown envelope format refused before storage, and idempotent `forget`.
|
|
219
|
+
*
|
|
220
|
+
* The one thing that FAILED was the second write to an existing session — the
|
|
221
|
+
* core job — because 9.29.0 patched `sessionState` and the service refuses
|
|
222
|
+
* that. The trial recovered the service's own words and verified the repair
|
|
223
|
+
* path (`appendEvent` with `actions.stateDelta`, then a `GET` showing the new
|
|
224
|
+
* state) with a raw diagnostic. This adapter now uses that verb; the repair is
|
|
225
|
+
* built on measured service behaviour and tested here, but the corrected write
|
|
226
|
+
* has not itself been re-run through this adapter in a live project.
|
|
155
227
|
*
|
|
156
228
|
* @example A standing agent whose conversations are shared across instances
|
|
157
229
|
* import { standingAgent, nodeHost } from 'agentfootprint/hosting';
|
|
@@ -14,23 +14,53 @@
|
|
|
14
14
|
* was designed under; where the product name and the API disagree, the API is
|
|
15
15
|
* the one that has not moved.
|
|
16
16
|
*
|
|
17
|
-
* ── The fit, and
|
|
17
|
+
* ── The fit, and the one thing it cost ──────────────────────────────────────
|
|
18
18
|
* `Session.sessionState` is an arbitrary JSON `Struct`. A `CheckpointEnvelope`
|
|
19
19
|
* is arbitrary JSON. So the envelope goes in whole, under one key, and comes
|
|
20
|
-
* back whole — no event log to fold, no blob encoding to get wrong
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* event blob comes back as somebody else's `toString()`.
|
|
20
|
+
* back whole — no event log to fold, no blob encoding to get wrong. What it
|
|
21
|
+
* cost is the WRITE VERB, and that took a field trial to learn: state goes in
|
|
22
|
+
* through an appended EVENT, never through a patch. See fact 2b below.
|
|
24
23
|
*
|
|
25
|
-
* ── The
|
|
24
|
+
* ── The five facts that shaped the code ─────────────────────────────────────
|
|
26
25
|
* 1. **`sessions.create` takes a caller-supplied `sessionId`.** So our session
|
|
27
26
|
* id IS the resource id and `hydrate` is one `get` by name. No mapping
|
|
28
27
|
* table, no listing to find a conversation.
|
|
29
28
|
* 2. **`create` and `delete` answer a long-running Operation; `get` and
|
|
30
|
-
* `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
29
|
+
* `appendEvent` answer directly.** Every operation-shaped write here waits
|
|
30
|
+
* for `done` before it returns — a `persist` that returned early would make
|
|
31
|
+
* the very next `hydrate` a race whose failure mode is "no conversation",
|
|
32
|
+
* which nobody can tell from a new user.
|
|
33
|
+
*
|
|
34
|
+
* 2b. **`sessionState` CANNOT be patched. This one is field truth, and it cost
|
|
35
|
+
* a release.** 9.29.0 wrote the steady state as
|
|
36
|
+
* `sessions.patch({ updateMask: 'sessionState,ttl' })`, which every
|
|
37
|
+
* injected-client test accepted because a double will patch anything. An
|
|
38
|
+
* independent field trial ran it against the live service (2026-08-14) and
|
|
39
|
+
* found that turn one stored and **every later turn failed**:
|
|
40
|
+
*
|
|
41
|
+
* HTTP 400 — "Can't update the session state for session …, you can only
|
|
42
|
+
* update it by appending an event."
|
|
43
|
+
*
|
|
44
|
+
* A store that keeps the first turn of a conversation and refuses the
|
|
45
|
+
* second is not a session store, so the verb changed rather than the
|
|
46
|
+
* documentation: `persist` now appends a `SessionEvent` whose
|
|
47
|
+
* `actions.stateDelta` carries the envelope, which the same trial verified
|
|
48
|
+
* end to end (append accepted, `GET` returned the new state).
|
|
49
|
+
*
|
|
50
|
+
* Two consequences worth saying out loud, because they are the difference
|
|
51
|
+
* between this fix and a plausible-looking one:
|
|
52
|
+
*
|
|
53
|
+
* • **A state delta MERGES by top-level key.** This store writes exactly
|
|
54
|
+
* one key — {@link SESSION_STATE_KEY} — so "merge the delta" and
|
|
55
|
+
* "replace our key" are the same outcome for us, and another guest's
|
|
56
|
+
* keys under the same session are left alone either way.
|
|
57
|
+
* • **A conversation now has an event log behind it**, one event per
|
|
58
|
+
* persisted turn, because that is the only writing surface the service
|
|
59
|
+
* offers. Nothing here READS that log — `hydrate` still reads the one
|
|
60
|
+
* envelope out of `sessionState` — so the log is the service's audit
|
|
61
|
+
* trail of our writes and never a second copy of the truth. Sessions
|
|
62
|
+
* are per-conversation and events are small; if that growth matters to
|
|
63
|
+
* you, `forget()` deletes the session and its events together.
|
|
34
64
|
* 3. **`Session.userId` is required and immutable.** Our port's
|
|
35
65
|
* `persist(sessionId, envelope)` carries no user, so one has to be
|
|
36
66
|
* resolved — see {@link AgentEngineSessionsOptions.userId}. Immutable
|
|
@@ -52,8 +82,15 @@
|
|
|
52
82
|
* before handing a session id down here. This adapter is a STORE. Nothing
|
|
53
83
|
* that only stores can tell an impostor from an owner.
|
|
54
84
|
* 4. **`ttl` is input-only with a 24-hour floor**, and `expireTime` always
|
|
55
|
-
* comes back.
|
|
56
|
-
*
|
|
85
|
+
* comes back. An hour-long TTL is not available at any price.
|
|
86
|
+
*
|
|
87
|
+
* **Sliding expiry is NOT claimed here**, and that changed with fact 2b. A
|
|
88
|
+
* `ttl` is sent on `create`, where the service takes it; later turns append
|
|
89
|
+
* an event, and whether an appended event renews the expiry is a service
|
|
90
|
+
* behaviour nothing in this repository has measured. Rather than send an
|
|
91
|
+
* unverified second call per turn to "refresh" it — a write whose only
|
|
92
|
+
* evidence would be that it did not error — the adapter sends the ttl once
|
|
93
|
+
* and says so. See {@link AgentEngineSessionsOptions.ttl}.
|
|
57
94
|
*
|
|
58
95
|
* ── The laws it inherits rather than re-implements ──────────────────────────
|
|
59
96
|
* `checkEnvelope` runs on the way OUT and on the way IN, so an envelope whose
|
|
@@ -79,13 +116,33 @@ const ADAPTER = 'agentEngineSessions';
|
|
|
79
116
|
export const SESSION_STATE_KEY = 'agentfootprint.envelope';
|
|
80
117
|
/** What a conversation that named nobody is stored under. */
|
|
81
118
|
export const DEFAULT_USER_ID = 'agentfootprint-anonymous';
|
|
119
|
+
/**
|
|
120
|
+
* The `author` on every event this store appends, unless
|
|
121
|
+
* {@link AgentEngineSessionsOptions.eventAuthor} names another.
|
|
122
|
+
*
|
|
123
|
+
* The service requires the field and treats it as free text. This name says
|
|
124
|
+
* which library wrote the turn, which is the useful thing to see in the console
|
|
125
|
+
* beside somebody else's agent writing to the same engine.
|
|
126
|
+
*/
|
|
127
|
+
export const SESSION_EVENT_AUTHOR = 'agentfootprint';
|
|
82
128
|
/**
|
|
83
129
|
* Conversations in Vertex AI's session service — the store that survives a
|
|
84
130
|
* fleet, not just a restart.
|
|
85
131
|
*
|
|
86
|
-
* **Status:
|
|
87
|
-
*
|
|
88
|
-
*
|
|
132
|
+
* **Status: field-validated except the write verb, which is field-CORRECTED.**
|
|
133
|
+
* An independent trial ran this adapter against a live Agent Runtime engine
|
|
134
|
+
* (2026-08-14) and everything below answered a real request from Google:
|
|
135
|
+
* creating first-turn sessions from real envelopes, hydrating them through a
|
|
136
|
+
* fresh instance, owners preserved, paged `listByUser` filtering, `ownerOf`,
|
|
137
|
+
* an unknown envelope format refused before storage, and idempotent `forget`.
|
|
138
|
+
*
|
|
139
|
+
* The one thing that FAILED was the second write to an existing session — the
|
|
140
|
+
* core job — because 9.29.0 patched `sessionState` and the service refuses
|
|
141
|
+
* that. The trial recovered the service's own words and verified the repair
|
|
142
|
+
* path (`appendEvent` with `actions.stateDelta`, then a `GET` showing the new
|
|
143
|
+
* state) with a raw diagnostic. This adapter now uses that verb; the repair is
|
|
144
|
+
* built on measured service behaviour and tested here, but the corrected write
|
|
145
|
+
* has not itself been re-run through this adapter in a live project.
|
|
89
146
|
*
|
|
90
147
|
* @example A standing agent whose conversations are shared across instances
|
|
91
148
|
* import { standingAgent, nodeHost } from 'agentfootprint/hosting';
|
|
@@ -116,6 +173,60 @@ export function agentEngineSessions(options) {
|
|
|
116
173
|
`bug rather than surface it. Build a new store if you need one after closing this.`);
|
|
117
174
|
};
|
|
118
175
|
const nameOf = (sessionId) => `${scope.parent}/sessions/${safeResourceId(sessionId)}`;
|
|
176
|
+
/**
|
|
177
|
+
* Does a session by this name exist? Asked ONLY to tell "there is nothing to
|
|
178
|
+
* append to" apart from "the append itself was refused".
|
|
179
|
+
*
|
|
180
|
+
* The live trial proved the two ends of the write path — `create` stores a
|
|
181
|
+
* new conversation, `appendEvent` updates an existing one — and left the
|
|
182
|
+
* middle unmeasured: what the service answers when you append to a session
|
|
183
|
+
* that is not there. Branching on an assumed 404 would put the FIRST turn of
|
|
184
|
+
* every conversation on a guess. So a failed append asks the resource itself,
|
|
185
|
+
* which is a fact rather than a convention, and costs one call on the one
|
|
186
|
+
* turn where the append was never going to work anyway.
|
|
187
|
+
*/
|
|
188
|
+
const missing = async (name) => {
|
|
189
|
+
try {
|
|
190
|
+
await sessions.get({ name });
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
// Anything that is not a clean "no such session" leaves the append's own
|
|
195
|
+
// failure standing — it is the one that says what went wrong.
|
|
196
|
+
return isNotFound(err);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Write the envelope onto an EXISTING session, as one appended event.
|
|
201
|
+
*
|
|
202
|
+
* Answers `false` — rather than raising — for the one case the caller has a
|
|
203
|
+
* repair for: there is no session here yet, so it has to be created.
|
|
204
|
+
*/
|
|
205
|
+
const append = async (name, stateDelta) => {
|
|
206
|
+
try {
|
|
207
|
+
await sessions.appendEvent({
|
|
208
|
+
name,
|
|
209
|
+
requestBody: {
|
|
210
|
+
author: options.eventAuthor ?? SESSION_EVENT_AUTHOR,
|
|
211
|
+
// Required, and one per persisted turn. It groups the events of one
|
|
212
|
+
// invocation on the service's side; this store writes exactly one
|
|
213
|
+
// event per turn, so a fresh id per call is the honest grouping.
|
|
214
|
+
invocationId: newInvocationId(),
|
|
215
|
+
timestamp: new Date().toISOString(),
|
|
216
|
+
// ONE top-level key — see the module header. A state delta merges by
|
|
217
|
+
// top-level key, so this replaces our envelope and touches nothing
|
|
218
|
+
// else in the struct.
|
|
219
|
+
actions: { stateDelta },
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
if (isNotFound(err) || (await missing(name)))
|
|
226
|
+
return false;
|
|
227
|
+
throw googleSdkFailure(ADAPTER, 'sessions.appendEvent', err);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
119
230
|
return {
|
|
120
231
|
parent: scope.parent,
|
|
121
232
|
async hydrate(sessionId) {
|
|
@@ -158,54 +269,42 @@ export function agentEngineSessions(options) {
|
|
|
158
269
|
// read back is one it has no business writing.
|
|
159
270
|
const checked = checkEnvelope(envelope, sessionId);
|
|
160
271
|
const name = nameOf(sessionId);
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
...(options.ttl !== undefined && { ttl: options.ttl }),
|
|
164
|
-
};
|
|
165
|
-
// PATCH first, CREATE on 404 — rather than the other way round.
|
|
272
|
+
const state = { [SESSION_STATE_KEY]: checked };
|
|
273
|
+
// APPEND first, CREATE when there is no session to append to.
|
|
166
274
|
//
|
|
167
|
-
// The steady state of a conversation is "it already exists":
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// Only the fields we own. Without a mask a patch is a REPLACE, and a
|
|
176
|
-
// replace would drop `userId` — which is immutable, so the service
|
|
177
|
-
// would refuse the write and a conversation would stop persisting.
|
|
178
|
-
updateMask: maskFor(body),
|
|
179
|
-
requestBody: body,
|
|
180
|
-
});
|
|
275
|
+
// The steady state of a conversation is "it already exists": created
|
|
276
|
+
// once, written on every turn after that. So the ordinary turn costs one
|
|
277
|
+
// call, and the extra call is paid on turn one only.
|
|
278
|
+
//
|
|
279
|
+
// Appending — not patching. `sessions.patch` with a `sessionState` mask is
|
|
280
|
+
// refused by the live service (module header, fact 2b); it is the verb
|
|
281
|
+
// 9.29.0 used and the reason a second turn could not be stored.
|
|
282
|
+
if (await append(name, state))
|
|
181
283
|
return;
|
|
182
|
-
}
|
|
183
|
-
catch (err) {
|
|
184
|
-
if (!isNotFound(err))
|
|
185
|
-
throw googleSdkFailure(ADAPTER, 'sessions.patch', err);
|
|
186
|
-
}
|
|
187
284
|
const userId = resolveUserId(sessionId, checked);
|
|
188
285
|
let created;
|
|
189
286
|
try {
|
|
190
287
|
created = await sessions.create({
|
|
191
288
|
parent: scope.parent,
|
|
192
289
|
sessionId: safeResourceId(sessionId),
|
|
193
|
-
requestBody: {
|
|
290
|
+
requestBody: {
|
|
291
|
+
sessionState: state,
|
|
292
|
+
...(options.ttl !== undefined && { ttl: options.ttl }),
|
|
293
|
+
userId,
|
|
294
|
+
},
|
|
194
295
|
});
|
|
195
296
|
}
|
|
196
297
|
catch (err) {
|
|
197
298
|
// Two writers opened the same conversation at once and the other one
|
|
198
299
|
// won. That is not a failure: the session exists now, which is all
|
|
199
|
-
// this call wanted, so
|
|
300
|
+
// this call wanted, so our state goes on with the same appended event.
|
|
200
301
|
if (!isAlreadyExists(err))
|
|
201
302
|
throw googleSdkFailure(ADAPTER, 'sessions.create', err);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
return;
|
|
303
|
+
if (await append(name, state))
|
|
304
|
+
return;
|
|
305
|
+
// Created by somebody and gone again before we could write to it.
|
|
306
|
+
// Nothing here can say this turn landed, so it does not say it.
|
|
307
|
+
throw googleSdkFailure(ADAPTER, 'sessions.create', err);
|
|
209
308
|
}
|
|
210
309
|
// OUTSIDE the try on purpose: this refusal is already sanitized and
|
|
211
310
|
// already says what to do, and re-wrapping it would replace a precise
|
|
@@ -348,17 +447,23 @@ function userIdResolver(option) {
|
|
|
348
447
|
return (_sessionId, envelope) => envelopeOwner(envelope) ?? DEFAULT_USER_ID;
|
|
349
448
|
}
|
|
350
449
|
/**
|
|
351
|
-
*
|
|
450
|
+
* A fresh `invocationId` for one appended event.
|
|
451
|
+
*
|
|
452
|
+
* The field is required and groups the events of one invocation on the
|
|
453
|
+
* service's side. This store writes exactly one event per persisted turn, so a
|
|
454
|
+
* new id per call is what that grouping honestly is — reusing one across turns
|
|
455
|
+
* would tell the console that a whole conversation was a single invocation.
|
|
352
456
|
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
457
|
+
* `randomUUID` where the runtime has it, and a time-plus-random id where it
|
|
458
|
+
* does not: this is a correlation label, not a security value, and an adapter
|
|
459
|
+
* that threw on an old runtime because a label could not be minted would be
|
|
460
|
+
* failing a conversation over nothing.
|
|
356
461
|
*/
|
|
357
|
-
function
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
return
|
|
462
|
+
function newInvocationId() {
|
|
463
|
+
const uuid = globalThis.crypto?.randomUUID;
|
|
464
|
+
if (typeof uuid === 'function')
|
|
465
|
+
return `af-${uuid.call(globalThis.crypto)}`;
|
|
466
|
+
return `af-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
362
467
|
}
|
|
363
468
|
/** The id out of a resource name, which is everything after the last `/`. */
|
|
364
469
|
function lastSegment(name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"googleAgentEngine.js","sourceRoot":"","sources":["../../../../src/adapters/hosting/googleAgentEngine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"googleAgentEngine.js","sourceRoot":"","sources":["../../../../src/adapters/hosting/googleAgentEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AAEH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAOlE,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,4BA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C,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,2EAA2E;AAC3E,SAAS,QAAQ,CAAC,KAAgC;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,6EAA6E;AAC7E,SAAS,QAAQ,CAAC,MAAe;IAC/B,MAAM,MAAM,GAAI,MAA2C,EAAE,MAAM,CAAC;IACpE,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC"}
|
|
@@ -151,10 +151,24 @@ export interface GoogleIdentityOptions {
|
|
|
151
151
|
/**
|
|
152
152
|
* Vend Google access tokens from whatever credential this environment has.
|
|
153
153
|
*
|
|
154
|
-
* **Status:
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
154
|
+
* **Status: field-validated for machine identity; refresh bounded.** An
|
|
155
|
+
* independent trial ran this adapter on live Google Cloud (2026-08-14):
|
|
156
|
+
* `googleIdentity({ services: ['aiplatform'] })` vended a real bearer
|
|
157
|
+
* credential from Application Default Credentials, and that credential
|
|
158
|
+
* authorized a Vertex AI request with HTTP 200. The same run proved the
|
|
159
|
+
* `bearer` kind, an expiry about 3,599 seconds out, a second vend without
|
|
160
|
+
* reconstruction, `mode: 'user'` failing CLOSED rather than quietly handing
|
|
161
|
+
* back machine access, a disallowed service failing closed, and
|
|
162
|
+
* `JSON.stringify(credential)` yielding `{"kind":"bearer"}` — no token, no
|
|
163
|
+
* Authorization header.
|
|
164
|
+
*
|
|
165
|
+
* **What is NOT proven:** an expiry-triggered refresh. The trial called the
|
|
166
|
+
* provider twice minutes apart and checked a future expiry; it did not wait an
|
|
167
|
+
* hour. Google's own auth client is what refreshes (this adapter caches the
|
|
168
|
+
* CLIENT, never a token — see {@link CachedGoogleClient}), and that refresh was
|
|
169
|
+
* field-proved on a different door (`gemini({ googleAuthOptions })`). A soak or
|
|
170
|
+
* a controlled expiring-credential double is still owed before anyone claims
|
|
171
|
+
* long-duration production proof for THIS provider.
|
|
158
172
|
*
|
|
159
173
|
* @throws when `mode: 'user'` is requested — Google's per-user token vault has
|
|
160
174
|
* no Node surface, and a machine token returned in its place would be a
|
|
@@ -62,10 +62,24 @@ export const CLOUD_PLATFORM_SCOPE = 'https://www.googleapis.com/auth/cloud-platf
|
|
|
62
62
|
/**
|
|
63
63
|
* Vend Google access tokens from whatever credential this environment has.
|
|
64
64
|
*
|
|
65
|
-
* **Status:
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
65
|
+
* **Status: field-validated for machine identity; refresh bounded.** An
|
|
66
|
+
* independent trial ran this adapter on live Google Cloud (2026-08-14):
|
|
67
|
+
* `googleIdentity({ services: ['aiplatform'] })` vended a real bearer
|
|
68
|
+
* credential from Application Default Credentials, and that credential
|
|
69
|
+
* authorized a Vertex AI request with HTTP 200. The same run proved the
|
|
70
|
+
* `bearer` kind, an expiry about 3,599 seconds out, a second vend without
|
|
71
|
+
* reconstruction, `mode: 'user'` failing CLOSED rather than quietly handing
|
|
72
|
+
* back machine access, a disallowed service failing closed, and
|
|
73
|
+
* `JSON.stringify(credential)` yielding `{"kind":"bearer"}` — no token, no
|
|
74
|
+
* Authorization header.
|
|
75
|
+
*
|
|
76
|
+
* **What is NOT proven:** an expiry-triggered refresh. The trial called the
|
|
77
|
+
* provider twice minutes apart and checked a future expiry; it did not wait an
|
|
78
|
+
* hour. Google's own auth client is what refreshes (this adapter caches the
|
|
79
|
+
* CLIENT, never a token — see {@link CachedGoogleClient}), and that refresh was
|
|
80
|
+
* field-proved on a different door (`gemini({ googleAuthOptions })`). A soak or
|
|
81
|
+
* a controlled expiring-credential double is still owed before anyone claims
|
|
82
|
+
* long-duration production proof for THIS provider.
|
|
69
83
|
*
|
|
70
84
|
* @throws when `mode: 'user'` is requested — Google's per-user token vault has
|
|
71
85
|
* no Node surface, and a machine token returned in its place would be a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../../src/adapters/identity/google.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAOjD,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAEjC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,gDAAgD,CAAC;AAwGrF
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../../src/adapters/identity/google.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAOjD,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAEjC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,gDAAgD,CAAC;AAwGrF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,cAAc,CAAC,UAAiC,EAAE;IAChE,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,SAAS,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O,0DAA0D;YAClE,+CAA+C;YAC/C,sFAAsF;YACtF,2BAA2B,CAC9B,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,GAAY;IACjC,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,IAAI,KAAK,CACvB,GAAG,OAAO,iEAAiE,IAAI,KAAK;QAClF,mFAAmF;QACnF,kFAAkF;QAClF,gFAAgF;QAChF,qEAAqE;QACrE,iFAAiF;QACjF,cAAc,CACjB,CAAC;IACF,OAAO,CAAC,IAAI,GAAG,mCAAmC,CAAC;IACnD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,0EAA0E;AAC1E,SAAS,UAAU,CAAC,SAAiB,EAAE,GAAY;IACjD,MAAM,OAAO,GAAG,IAAI,KAAK,CACvB,GAAG,OAAO,KAAK,SAAS,aAAa,SAAS,CAAC,GAAG,CAAC,KAAK;QACtD,oFAAoF;QACpF,0FAA0F,CAC7F,CAAC;IACF,OAAO,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACvC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,SAAS,CAAC,GAAY;IAC7B,MAAM,IAAI,GAAI,GAAiC,EAAE,IAAI,CAAC;IACtD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACnF,CAAC"}
|
|
@@ -40,9 +40,14 @@
|
|
|
40
40
|
* 429 for AI Studio prepayment, which is billing SEPARATE from the Google
|
|
41
41
|
* Cloud account's credit. What that door does with a funded key is
|
|
42
42
|
* untested here, which is why it has no default model.
|
|
43
|
-
* • **Tool calling on a 3.x model
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* • **Tool calling on a 3.x model: field-validated.** The signature round trip
|
|
44
|
+
* below was built from the trial's captured 400, and the same independent
|
|
45
|
+
* trial then re-ran it on live Vertex against the published fix
|
|
46
|
+
* (2026-08-14): `gemini-3.1-flash-lite` called a tool, the tool answered,
|
|
47
|
+
* the signature went back byte for byte, and the second model call
|
|
48
|
+
* completed with the right answer — two LLM calls, one tool execution, real
|
|
49
|
+
* token counts. What it does NOT cover is a signature attached to a TEXT
|
|
50
|
+
* part with no function call beside it; see below.
|
|
46
51
|
*
|
|
47
52
|
* ─── Why native, and not `openai({ baseURL })` ──────────────────────
|
|
48
53
|
*
|
|
@@ -40,9 +40,14 @@
|
|
|
40
40
|
* 429 for AI Studio prepayment, which is billing SEPARATE from the Google
|
|
41
41
|
* Cloud account's credit. What that door does with a funded key is
|
|
42
42
|
* untested here, which is why it has no default model.
|
|
43
|
-
* • **Tool calling on a 3.x model
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* • **Tool calling on a 3.x model: field-validated.** The signature round trip
|
|
44
|
+
* below was built from the trial's captured 400, and the same independent
|
|
45
|
+
* trial then re-ran it on live Vertex against the published fix
|
|
46
|
+
* (2026-08-14): `gemini-3.1-flash-lite` called a tool, the tool answered,
|
|
47
|
+
* the signature went back byte for byte, and the second model call
|
|
48
|
+
* completed with the right answer — two LLM calls, one tool execution, real
|
|
49
|
+
* token counts. What it does NOT cover is a signature attached to a TEXT
|
|
50
|
+
* part with no function call beside it; see below.
|
|
46
51
|
*
|
|
47
52
|
* ─── Why native, and not `openai({ baseURL })` ──────────────────────
|
|
48
53
|
*
|