@kindgi/agents 0.1.2 → 0.1.4-rc.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/blocks.d.ts +101 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +149 -0
- package/dist/blocks.js.map +1 -0
- package/dist/conversation-binding.d.ts +9 -1
- package/dist/conversation-binding.d.ts.map +1 -1
- package/dist/define.d.ts +17 -2
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +93 -6
- package/dist/define.js.map +1 -1
- package/dist/guardrails-gate.d.ts +7 -4
- package/dist/guardrails-gate.d.ts.map +1 -1
- package/dist/guardrails-gate.js +5 -2
- package/dist/guardrails-gate.js.map +1 -1
- package/dist/handlers/compose-result.d.ts.map +1 -1
- package/dist/handlers/compose-result.js +3 -0
- package/dist/handlers/compose-result.js.map +1 -1
- package/dist/handlers/context.d.ts +24 -0
- package/dist/handlers/context.d.ts.map +1 -1
- package/dist/handlers/dispatch-tools.d.ts.map +1 -1
- package/dist/handlers/dispatch-tools.js +69 -43
- package/dist/handlers/dispatch-tools.js.map +1 -1
- package/dist/handlers/errors.d.ts +12 -1
- package/dist/handlers/errors.d.ts.map +1 -1
- package/dist/handlers/errors.js.map +1 -1
- package/dist/handlers/evaluate-guardrails.d.ts.map +1 -1
- package/dist/handlers/evaluate-guardrails.js +36 -1
- package/dist/handlers/evaluate-guardrails.js.map +1 -1
- package/dist/handlers/gate-decision.d.ts +62 -0
- package/dist/handlers/gate-decision.d.ts.map +1 -0
- package/dist/handlers/gate-decision.js +55 -0
- package/dist/handlers/gate-decision.js.map +1 -0
- package/dist/handlers/model-call.d.ts +10 -0
- package/dist/handlers/model-call.d.ts.map +1 -1
- package/dist/handlers/model-call.js +120 -34
- package/dist/handlers/model-call.js.map +1 -1
- package/dist/handlers/persist-provenance.d.ts.map +1 -1
- package/dist/handlers/persist-provenance.js +3 -1
- package/dist/handlers/persist-provenance.js.map +1 -1
- package/dist/handlers/persist-user-message.d.ts.map +1 -1
- package/dist/handlers/persist-user-message.js +5 -16
- package/dist/handlers/persist-user-message.js.map +1 -1
- package/dist/handlers/public-types.d.ts +37 -3
- package/dist/handlers/public-types.d.ts.map +1 -1
- package/dist/handlers/rehydrate.d.ts.map +1 -1
- package/dist/handlers/rehydrate.js +91 -1
- package/dist/handlers/rehydrate.js.map +1 -1
- package/dist/handlers/render-prompt.d.ts.map +1 -1
- package/dist/handlers/render-prompt.js +4 -1
- package/dist/handlers/render-prompt.js.map +1 -1
- package/dist/handlers/replay.d.ts +143 -0
- package/dist/handlers/replay.d.ts.map +1 -0
- package/dist/handlers/replay.js +177 -0
- package/dist/handlers/replay.js.map +1 -0
- package/dist/handlers/resolve-blocks.d.ts +32 -0
- package/dist/handlers/resolve-blocks.d.ts.map +1 -0
- package/dist/handlers/resolve-blocks.js +129 -0
- package/dist/handlers/resolve-blocks.js.map +1 -0
- package/dist/handlers/resolve-tools.d.ts +6 -2
- package/dist/handlers/resolve-tools.d.ts.map +1 -1
- package/dist/handlers/resolve-tools.js +59 -27
- package/dist/handlers/resolve-tools.js.map +1 -1
- package/dist/handlers/result-shape.d.ts +7 -0
- package/dist/handlers/result-shape.d.ts.map +1 -1
- package/dist/handlers/result-shape.js.map +1 -1
- package/dist/handlers/run-retrievals.d.ts.map +1 -1
- package/dist/handlers/run-retrievals.js +35 -35
- package/dist/handlers/run-retrievals.js.map +1 -1
- package/dist/handlers/run-snapshot.d.ts.map +1 -1
- package/dist/handlers/run-snapshot.js +1 -0
- package/dist/handlers/run-snapshot.js.map +1 -1
- package/dist/handlers/setup.d.ts +2 -0
- package/dist/handlers/setup.d.ts.map +1 -1
- package/dist/handlers/setup.js +29 -12
- package/dist/handlers/setup.js.map +1 -1
- package/dist/handlers/tool-hitl.d.ts +5 -9
- package/dist/handlers/tool-hitl.d.ts.map +1 -1
- package/dist/handlers/tool-hitl.js +5 -0
- package/dist/handlers/tool-hitl.js.map +1 -1
- package/dist/handlers/turn-environment.d.ts +13 -2
- package/dist/handlers/turn-environment.d.ts.map +1 -1
- package/dist/handlers/turn-environment.js +12 -3
- package/dist/handlers/turn-environment.js.map +1 -1
- package/dist/handlers/turn-provenance.d.ts +67 -0
- package/dist/handlers/turn-provenance.d.ts.map +1 -0
- package/dist/handlers/turn-provenance.js +160 -0
- package/dist/handlers/turn-provenance.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/invoke.d.ts +14 -1
- package/dist/invoke.d.ts.map +1 -1
- package/dist/invoke.js +37 -19
- package/dist/invoke.js.map +1 -1
- package/dist/pins.d.ts +54 -0
- package/dist/pins.d.ts.map +1 -0
- package/dist/pins.js +51 -0
- package/dist/pins.js.map +1 -0
- package/dist/prompt.d.ts +12 -2
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +41 -4
- package/dist/prompt.js.map +1 -1
- package/dist/provenance-emit.d.ts +4 -2
- package/dist/provenance-emit.d.ts.map +1 -1
- package/dist/provenance-emit.js +4 -2
- package/dist/provenance-emit.js.map +1 -1
- package/dist/run-snapshot-binding.d.ts +5 -0
- package/dist/run-snapshot-binding.d.ts.map +1 -1
- package/dist/schema.d.ts +34 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +16 -0
- package/dist/schema.js.map +1 -1
- package/dist/streaming.d.ts +5 -0
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js.map +1 -1
- package/dist/types.d.ts +65 -2
- package/dist/types.d.ts.map +1 -1
- package/migrations/0003_hesitant_captain_cross.sql +2 -0
- package/migrations/0004_stormy_moondragon.sql +1 -0
- package/migrations/meta/0003_snapshot.json +321 -0
- package/migrations/meta/0004_snapshot.json +327 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +15 -15
- package/src/blocks.ts +231 -0
- package/src/conversation-binding.ts +9 -1
- package/src/define.ts +104 -7
- package/src/guardrails-gate.ts +17 -3
- package/src/handlers/compose-result.ts +3 -0
- package/src/handlers/context.ts +24 -0
- package/src/handlers/dispatch-tools.ts +75 -44
- package/src/handlers/errors.ts +13 -0
- package/src/handlers/evaluate-guardrails.ts +41 -1
- package/src/handlers/gate-decision.ts +101 -0
- package/src/handlers/model-call.ts +163 -33
- package/src/handlers/persist-provenance.ts +3 -1
- package/src/handlers/persist-user-message.ts +3 -16
- package/src/handlers/public-types.ts +38 -3
- package/src/handlers/rehydrate.ts +141 -9
- package/src/handlers/render-prompt.ts +13 -7
- package/src/handlers/replay.ts +314 -0
- package/src/handlers/resolve-blocks.ts +188 -0
- package/src/handlers/resolve-tools.ts +76 -28
- package/src/handlers/result-shape.ts +8 -0
- package/src/handlers/run-retrievals.ts +45 -41
- package/src/handlers/run-snapshot.ts +1 -0
- package/src/handlers/setup.ts +30 -22
- package/src/handlers/tool-hitl.ts +6 -10
- package/src/handlers/turn-environment.ts +28 -3
- package/src/handlers/turn-provenance.ts +230 -0
- package/src/index.ts +44 -0
- package/src/invoke.ts +49 -20
- package/src/pins.ts +98 -0
- package/src/prompt.ts +52 -4
- package/src/provenance-emit.ts +4 -1
- package/src/run-snapshot-binding.ts +6 -0
- package/src/schema.ts +16 -0
- package/src/streaming.ts +5 -0
- package/src/types.ts +68 -2
package/src/provenance-emit.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
Provenance,
|
|
7
7
|
ProvenanceBuilder,
|
|
8
8
|
ProvenanceEmitBinding,
|
|
9
|
+
ProvenanceEmitContext,
|
|
9
10
|
} from '@kindgi/provenance';
|
|
10
11
|
import { signProvenance } from '@kindgi/provenance';
|
|
11
12
|
import type { Result } from '@kindgi/types';
|
|
@@ -55,6 +56,8 @@ export interface ProvenanceBindings {
|
|
|
55
56
|
export async function persistProvenance(
|
|
56
57
|
builder: ProvenanceBuilder,
|
|
57
58
|
bindings: ProvenanceBindings,
|
|
59
|
+
/** Stored beside the record (the turn's project); see `ProvenanceEmitContext`. */
|
|
60
|
+
context?: ProvenanceEmitContext,
|
|
58
61
|
): Promise<Result<Provenance, PersistenceError>> {
|
|
59
62
|
let provenance: Provenance = builder.snapshot();
|
|
60
63
|
if (bindings.keyProvider !== undefined) {
|
|
@@ -84,7 +87,7 @@ export async function persistProvenance(
|
|
|
84
87
|
},
|
|
85
88
|
};
|
|
86
89
|
}
|
|
87
|
-
const emitted = await bindings.emitBinding.emit(provenance);
|
|
90
|
+
const emitted = await bindings.emitBinding.emit(provenance, context);
|
|
88
91
|
if (emitted.kind === 'err') {
|
|
89
92
|
return {
|
|
90
93
|
kind: 'err',
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import type { ProjectId, Result, RunId, Semver, TenantId, Timestamp } from '@kindgi/types';
|
|
5
5
|
|
|
6
|
+
import type { RunReplayRef } from '@kindgi/runtime';
|
|
7
|
+
|
|
6
8
|
import type { PersistenceError } from './errors.js';
|
|
7
9
|
import type { AgentId, ConversationId } from './types.js';
|
|
8
10
|
|
|
@@ -37,6 +39,8 @@ export interface RunSnapshotWriteInput {
|
|
|
37
39
|
* as `principal`.
|
|
38
40
|
*/
|
|
39
41
|
readonly authz?: unknown;
|
|
42
|
+
/** The turn's replay marker (`InvokeAgentInput.replay`): a resumed replay stays one. */
|
|
43
|
+
readonly replay?: RunReplayRef;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
/**
|
|
@@ -59,6 +63,8 @@ export interface RunSnapshotRecord {
|
|
|
59
63
|
readonly dryRun: boolean;
|
|
60
64
|
readonly principal?: unknown;
|
|
61
65
|
readonly authz?: unknown;
|
|
66
|
+
/** The turn's replay marker (`InvokeAgentInput.replay`): a resumed replay stays one. */
|
|
67
|
+
readonly replay?: RunReplayRef;
|
|
62
68
|
readonly createdAt: Timestamp;
|
|
63
69
|
}
|
|
64
70
|
|
package/src/schema.ts
CHANGED
|
@@ -43,6 +43,13 @@ export const agentConversations = pgTable(
|
|
|
43
43
|
* SSO subject). Kept as text so the caller decides the shape.
|
|
44
44
|
*/
|
|
45
45
|
participantId: text('participant_id'),
|
|
46
|
+
/**
|
|
47
|
+
* The project the conversation is in, set when it is opened (a run
|
|
48
|
+
* opens it in the run's project). Null when opened without one, and
|
|
49
|
+
* on conversations from before the column (nothing is backfilled).
|
|
50
|
+
* No foreign key: `projects` belongs to the runtime's schema.
|
|
51
|
+
*/
|
|
52
|
+
projectId: uuid('project_id'),
|
|
46
53
|
/**
|
|
47
54
|
* Structural scope — project id, matter id, etc. Persisted through
|
|
48
55
|
* the versioning envelope so shape evolution is migrate-on-read.
|
|
@@ -74,6 +81,10 @@ export const agentConversations = pgTable(
|
|
|
74
81
|
t.tenantId,
|
|
75
82
|
t.participantId,
|
|
76
83
|
),
|
|
84
|
+
/** One project's conversations, newest first (`listConversationsPage({ scope })`). */
|
|
85
|
+
tenantProjectOpenedIdx: index('agent_conversations_tenant_project_opened_idx')
|
|
86
|
+
.on(t.tenantId, t.projectId, t.openedAt.desc())
|
|
87
|
+
.where(sql`${t.projectId} IS NOT NULL`),
|
|
77
88
|
/** Partial index: open conversations sorted by recency. Used by the UI list. */
|
|
78
89
|
openRecentIdx: index('agent_conversations_open_recent_idx')
|
|
79
90
|
.on(t.tenantId, t.lastMessageAt.desc())
|
|
@@ -137,6 +148,11 @@ export const agentRunSnapshots = pgTable(
|
|
|
137
148
|
* Threaded back into the resumed TurnContext.
|
|
138
149
|
*/
|
|
139
150
|
authz: jsonb('authz'),
|
|
151
|
+
/**
|
|
152
|
+
* The replay marker (`{of, evalRunId}`) of a replay turn, so a resumed
|
|
153
|
+
* replay stays one: its tool calls are still decided by the replay rules.
|
|
154
|
+
*/
|
|
155
|
+
replay: jsonb('replay'),
|
|
140
156
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
141
157
|
},
|
|
142
158
|
(t) => ({
|
package/src/streaming.ts
CHANGED
|
@@ -86,6 +86,11 @@ export interface ToolCompletedEvent {
|
|
|
86
86
|
readonly invocationId: string;
|
|
87
87
|
readonly output: unknown;
|
|
88
88
|
readonly durationMs: number;
|
|
89
|
+
/**
|
|
90
|
+
* In a replay turn: whether the tool ran (`live`), the past run's result
|
|
91
|
+
* was used (`recorded`), or the call was refused (`refused`).
|
|
92
|
+
*/
|
|
93
|
+
readonly replay?: 'live' | 'recorded' | 'refused';
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
export interface ToolFailedEvent {
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
import type { Capability } from '@kindgi/capabilities';
|
|
5
5
|
import type { Fact, MemoryScope } from '@kindgi/memory';
|
|
6
6
|
import type { ToolErrorsSpec, ToolHitlMode, ToolHitlRule } from '@kindgi/policy-contract';
|
|
7
|
-
import type { Brand, ConversationId, Semver, TenantId, Timestamp } from '@kindgi/types';
|
|
7
|
+
import type { Brand, ConversationId, ProjectId, Semver, TenantId, Timestamp } from '@kindgi/types';
|
|
8
|
+
|
|
9
|
+
import type { AgentDerivation, AgentPins } from './pins.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Branded agent id. Convention: dotted namespace under the tenant's
|
|
@@ -121,6 +123,22 @@ export interface ToolRef {
|
|
|
121
123
|
readonly version: string;
|
|
122
124
|
}
|
|
123
125
|
|
|
126
|
+
/**
|
|
127
|
+
* A prompt block an agent's instructions come from: its id and a semver
|
|
128
|
+
* range, resolved like a tool's (`pickVersion`) and pinned when the
|
|
129
|
+
* agent version is published.
|
|
130
|
+
*/
|
|
131
|
+
export interface PromptRef {
|
|
132
|
+
readonly prompt: string;
|
|
133
|
+
readonly version: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A settings block an agent reads: its id and a semver range, pinned at publish. */
|
|
137
|
+
export interface BlockRef {
|
|
138
|
+
readonly id: string;
|
|
139
|
+
readonly version: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
124
142
|
/**
|
|
125
143
|
* Per-agent behavior for multi-turn conversations. The agent chooses:
|
|
126
144
|
* - How many prior messages to load (`historyLimit`; unset = all).
|
|
@@ -204,6 +222,14 @@ export interface ConversationHitlPolicy {
|
|
|
204
222
|
* (see `resolveEffectiveHitlPolicy`).
|
|
205
223
|
*/
|
|
206
224
|
readonly timeoutMs?: number;
|
|
225
|
+
/**
|
|
226
|
+
* What happens when an approval's time runs out: it escalates one
|
|
227
|
+
* reviewer tier, and at `admin` it expires (the turn fails with
|
|
228
|
+
* `hitl-cancelled`). `'escalate'` is the only behavior today, and the
|
|
229
|
+
* default; `'auto-approve'` and `'auto-reject'` are refused rather than
|
|
230
|
+
* accepted and ignored.
|
|
231
|
+
*/
|
|
232
|
+
readonly onTimeout?: 'escalate';
|
|
207
233
|
}
|
|
208
234
|
|
|
209
235
|
/**
|
|
@@ -284,8 +310,13 @@ export interface Agent {
|
|
|
284
310
|
* unresolved reference fails the turn at invoke time
|
|
285
311
|
* (`model-invocation-failed` whose `cause` is the `missing-parameter`
|
|
286
312
|
* render error), never a silent empty string.
|
|
313
|
+
*
|
|
314
|
+
* Or a prompt block, by range (`{ prompt: 'acme.intake-prompt',
|
|
315
|
+
* version: '^1.0.0' }`): its template renders here instead, with the
|
|
316
|
+
* parameters it declares, and the version that runs is pinned when the
|
|
317
|
+
* agent version is published (`pins.prompts`).
|
|
287
318
|
*/
|
|
288
|
-
readonly instructions: string;
|
|
319
|
+
readonly instructions: string | PromptRef;
|
|
289
320
|
/**
|
|
290
321
|
* Typed parameters the caller supplies at invoke time. The UI reads
|
|
291
322
|
* this to build a "configure agent" form; the runtime validates each
|
|
@@ -397,6 +428,35 @@ export interface Agent {
|
|
|
397
428
|
* A tenant's `tool-errors` policy can lower it. See `ToolErrorsSpec`.
|
|
398
429
|
*/
|
|
399
430
|
readonly toolErrors?: ToolErrorsSpec;
|
|
431
|
+
/**
|
|
432
|
+
* The exact block versions this agent version runs, resolved by the
|
|
433
|
+
* runtime when the version was published (see `AgentPins`). Never
|
|
434
|
+
* authored: `defineAgent` doesn't take it. Absent on an agent defined
|
|
435
|
+
* in code and on a version published before pins existed; its tool
|
|
436
|
+
* ranges then resolve per run.
|
|
437
|
+
*/
|
|
438
|
+
readonly pins?: AgentPins;
|
|
439
|
+
/**
|
|
440
|
+
* Settings blocks the agent reads, by range. Each block's values reach
|
|
441
|
+
* its tools as `ToolContext.settings[<block id>]` and its templates as
|
|
442
|
+
* `settings.<block id>.<key>`; the versions are pinned at publish
|
|
443
|
+
* (`pins.settings`).
|
|
444
|
+
*/
|
|
445
|
+
readonly settings?: readonly BlockRef[];
|
|
446
|
+
/**
|
|
447
|
+
* A settings block of model settings (`MODEL_SETTINGS_SCHEMA`:
|
|
448
|
+
* `temperature`, `maxOutputTokens`) the turn's model calls use. Pinned
|
|
449
|
+
* at publish with the other settings.
|
|
450
|
+
*/
|
|
451
|
+
readonly modelSettings?: BlockRef;
|
|
452
|
+
/** `pinsDigest(pins)`, recorded when the version was published. */
|
|
453
|
+
readonly pinsDigest?: string;
|
|
454
|
+
/**
|
|
455
|
+
* Set by the runtime on a version it registered under another number
|
|
456
|
+
* than the definition's, when a deploy couldn't register that number
|
|
457
|
+
* as it was (see `AgentDerivation`). Never authored.
|
|
458
|
+
*/
|
|
459
|
+
readonly derivedFrom?: AgentDerivation;
|
|
400
460
|
}
|
|
401
461
|
|
|
402
462
|
/**
|
|
@@ -416,6 +476,12 @@ export interface Conversation {
|
|
|
416
476
|
readonly title: string;
|
|
417
477
|
/** UUID or free-form identifier for the human participant. */
|
|
418
478
|
readonly participantId?: string;
|
|
479
|
+
/**
|
|
480
|
+
* The project the conversation is in, set when it is opened (by a run,
|
|
481
|
+
* from the run's project). Absent on conversations opened without one,
|
|
482
|
+
* and on those from before it was stored.
|
|
483
|
+
*/
|
|
484
|
+
readonly projectId?: ProjectId;
|
|
419
485
|
/** Additional attributes (project id, matter id, etc.). */
|
|
420
486
|
readonly scope: MemoryScope;
|
|
421
487
|
readonly openedAt: Timestamp;
|