@kindgi/api 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/agent-binding.d.ts +18 -4
- package/dist/agent-binding.d.ts.map +1 -1
- package/dist/agent-pins.d.ts +48 -0
- package/dist/agent-pins.d.ts.map +1 -0
- package/dist/agent-pins.js +102 -0
- package/dist/agent-pins.js.map +1 -0
- package/dist/app.d.ts +22 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +22 -3
- package/dist/app.js.map +1 -1
- package/dist/block-binding.d.ts +132 -0
- package/dist/block-binding.d.ts.map +1 -0
- package/dist/block-binding.js +4 -0
- package/dist/block-binding.js.map +1 -0
- package/dist/block-pins.d.ts +22 -0
- package/dist/block-pins.d.ts.map +1 -0
- package/dist/block-pins.js +112 -0
- package/dist/block-pins.js.map +1 -0
- package/dist/cost-binding.d.ts +100 -5
- package/dist/cost-binding.d.ts.map +1 -1
- package/dist/cost-binding.js +10 -0
- package/dist/cost-binding.js.map +1 -1
- package/dist/deploy-versions.d.ts +58 -0
- package/dist/deploy-versions.d.ts.map +1 -0
- package/dist/deploy-versions.js +91 -0
- package/dist/deploy-versions.js.map +1 -0
- package/dist/deployment-binding.d.ts +24 -3
- package/dist/deployment-binding.d.ts.map +1 -1
- package/dist/derive-agent-version.d.ts +69 -0
- package/dist/derive-agent-version.d.ts.map +1 -0
- package/dist/derive-agent-version.js +139 -0
- package/dist/derive-agent-version.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -1
- package/dist/eval-case-binding.d.ts +65 -0
- package/dist/eval-case-binding.d.ts.map +1 -0
- package/dist/eval-case-binding.js +4 -0
- package/dist/eval-case-binding.js.map +1 -0
- package/dist/eval-run-binding.d.ts +30 -0
- package/dist/eval-run-binding.d.ts.map +1 -1
- package/dist/eval-run-dispatcher.d.ts +38 -3
- package/dist/eval-run-dispatcher.d.ts.map +1 -1
- package/dist/eval-run-dispatcher.js +21 -15
- package/dist/eval-run-dispatcher.js.map +1 -1
- package/dist/eval-suite-binding.d.ts +1 -1
- package/dist/eval-suite-binding.d.ts.map +1 -1
- package/dist/eval-suite-binding.js +2 -0
- package/dist/eval-suite-binding.js.map +1 -1
- package/dist/flow-binding.d.ts +10 -4
- package/dist/flow-binding.d.ts.map +1 -1
- package/dist/flow-pins.d.ts +36 -0
- package/dist/flow-pins.d.ts.map +1 -0
- package/dist/flow-pins.js +81 -0
- package/dist/flow-pins.js.map +1 -0
- package/dist/hitl-binding.d.ts +20 -5
- package/dist/hitl-binding.d.ts.map +1 -1
- package/dist/index.d.ts +19 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/judged-dispatcher.d.ts +134 -0
- package/dist/judged-dispatcher.d.ts.map +1 -0
- package/dist/judged-dispatcher.js +297 -0
- package/dist/judged-dispatcher.js.map +1 -0
- package/dist/judged-items.d.ts +86 -0
- package/dist/judged-items.d.ts.map +1 -0
- package/dist/judged-items.js +184 -0
- package/dist/judged-items.js.map +1 -0
- package/dist/judgment-binding.d.ts +316 -0
- package/dist/judgment-binding.d.ts.map +1 -0
- package/dist/judgment-binding.js +19 -0
- package/dist/judgment-binding.js.map +1 -0
- package/dist/middleware/auth.d.ts +3 -2
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/idempotency.d.ts +5 -1
- package/dist/middleware/idempotency.d.ts.map +1 -1
- package/dist/middleware/idempotency.js +8 -1
- package/dist/middleware/idempotency.js.map +1 -1
- package/dist/openapi/generate.d.ts.map +1 -1
- package/dist/openapi/generate.js +4 -1
- package/dist/openapi/generate.js.map +1 -1
- package/dist/openapi/operations.d.ts.map +1 -1
- package/dist/openapi/operations.js +543 -24
- package/dist/openapi/operations.js.map +1 -1
- package/dist/openapi/schemas.d.ts +58 -0
- package/dist/openapi/schemas.d.ts.map +1 -1
- package/dist/openapi/schemas.js +1058 -27
- package/dist/openapi/schemas.js.map +1 -1
- package/dist/provenance-binding.d.ts +27 -1
- package/dist/provenance-binding.d.ts.map +1 -1
- package/dist/provenance-binding.js.map +1 -1
- package/dist/provider-binding.d.ts +12 -7
- package/dist/provider-binding.d.ts.map +1 -1
- package/dist/reviewer-binding.d.ts +10 -2
- package/dist/reviewer-binding.d.ts.map +1 -1
- package/dist/reviewer-role.d.ts +13 -0
- package/dist/reviewer-role.d.ts.map +1 -0
- package/dist/reviewer-role.js +27 -0
- package/dist/reviewer-role.js.map +1 -0
- package/dist/routes/agents.d.ts +9 -1
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/agents.js +175 -11
- package/dist/routes/agents.js.map +1 -1
- package/dist/routes/approvals.d.ts +5 -4
- package/dist/routes/approvals.d.ts.map +1 -1
- package/dist/routes/approvals.js +52 -16
- package/dist/routes/approvals.js.map +1 -1
- package/dist/routes/blocks.d.ts +19 -0
- package/dist/routes/blocks.d.ts.map +1 -0
- package/dist/routes/blocks.js +281 -0
- package/dist/routes/blocks.js.map +1 -0
- package/dist/routes/conversations.d.ts +7 -1
- package/dist/routes/conversations.d.ts.map +1 -1
- package/dist/routes/conversations.js +41 -1
- package/dist/routes/conversations.js.map +1 -1
- package/dist/routes/cost.d.ts.map +1 -1
- package/dist/routes/cost.js +142 -11
- package/dist/routes/cost.js.map +1 -1
- package/dist/routes/deployments.d.ts +3 -0
- package/dist/routes/deployments.d.ts.map +1 -1
- package/dist/routes/deployments.js +208 -55
- package/dist/routes/deployments.js.map +1 -1
- package/dist/routes/eval-comparison.d.ts +14 -0
- package/dist/routes/eval-comparison.d.ts.map +1 -0
- package/dist/routes/eval-comparison.js +87 -0
- package/dist/routes/eval-comparison.js.map +1 -0
- package/dist/routes/eval-runs.d.ts.map +1 -1
- package/dist/routes/eval-runs.js +8 -0
- package/dist/routes/eval-runs.js.map +1 -1
- package/dist/routes/flows.d.ts +13 -1
- package/dist/routes/flows.d.ts.map +1 -1
- package/dist/routes/flows.js +44 -3
- package/dist/routes/flows.js.map +1 -1
- package/dist/routes/hierarchy-errors.d.ts +35 -0
- package/dist/routes/hierarchy-errors.d.ts.map +1 -0
- package/dist/routes/hierarchy-errors.js +39 -0
- package/dist/routes/hierarchy-errors.js.map +1 -0
- package/dist/routes/identity.d.ts +7 -0
- package/dist/routes/identity.d.ts.map +1 -1
- package/dist/routes/identity.js +3 -2
- package/dist/routes/identity.js.map +1 -1
- package/dist/routes/judged-suites.d.ts +20 -0
- package/dist/routes/judged-suites.d.ts.map +1 -0
- package/dist/routes/judged-suites.js +272 -0
- package/dist/routes/judged-suites.js.map +1 -0
- package/dist/routes/judgment-context.d.ts +22 -0
- package/dist/routes/judgment-context.d.ts.map +1 -0
- package/dist/routes/judgment-context.js +88 -0
- package/dist/routes/judgment-context.js.map +1 -0
- package/dist/routes/judgment-flow-context.d.ts +32 -0
- package/dist/routes/judgment-flow-context.d.ts.map +1 -0
- package/dist/routes/judgment-flow-context.js +195 -0
- package/dist/routes/judgment-flow-context.js.map +1 -0
- package/dist/routes/judgments.d.ts +41 -0
- package/dist/routes/judgments.d.ts.map +1 -0
- package/dist/routes/judgments.js +566 -0
- package/dist/routes/judgments.js.map +1 -0
- package/dist/routes/orgs.d.ts +5 -2
- package/dist/routes/orgs.d.ts.map +1 -1
- package/dist/routes/orgs.js +38 -22
- package/dist/routes/orgs.js.map +1 -1
- package/dist/routes/policies.d.ts.map +1 -1
- package/dist/routes/policies.js +12 -1
- package/dist/routes/policies.js.map +1 -1
- package/dist/routes/projects.d.ts +10 -2
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +87 -79
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provenance.d.ts.map +1 -1
- package/dist/routes/provenance.js +32 -1
- package/dist/routes/provenance.js.map +1 -1
- package/dist/routes/providers.d.ts.map +1 -1
- package/dist/routes/providers.js +6 -1
- package/dist/routes/providers.js.map +1 -1
- package/dist/routes/runs.d.ts +0 -7
- package/dist/routes/runs.d.ts.map +1 -1
- package/dist/routes/runs.js +65 -20
- package/dist/routes/runs.js.map +1 -1
- package/dist/routes/scope-params.d.ts +16 -1
- package/dist/routes/scope-params.d.ts.map +1 -1
- package/dist/routes/scope-params.js +28 -0
- package/dist/routes/scope-params.js.map +1 -1
- package/dist/routes/teams.d.ts +6 -2
- package/dist/routes/teams.d.ts.map +1 -1
- package/dist/routes/teams.js +77 -73
- package/dist/routes/teams.js.map +1 -1
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/webhook-endpoint-binding.d.ts +11 -0
- package/dist/webhook-endpoint-binding.d.ts.map +1 -1
- package/dist/webhook-endpoint-binding.js.map +1 -1
- package/openapi.json +13316 -9299
- package/package.json +21 -21
- package/src/agent-binding.ts +19 -4
- package/src/agent-pins.ts +147 -0
- package/src/app.ts +76 -3
- package/src/block-binding.ts +137 -0
- package/src/block-pins.ts +148 -0
- package/src/cost-binding.ts +116 -5
- package/src/deploy-versions.ts +157 -0
- package/src/deployment-binding.ts +27 -3
- package/src/derive-agent-version.ts +206 -0
- package/src/errors.ts +17 -0
- package/src/eval-case-binding.ts +71 -0
- package/src/eval-run-binding.ts +33 -0
- package/src/eval-run-dispatcher.ts +57 -16
- package/src/eval-suite-binding.ts +2 -0
- package/src/flow-binding.ts +11 -4
- package/src/flow-pins.ts +113 -0
- package/src/hitl-binding.ts +20 -4
- package/src/index.ts +88 -2
- package/src/judged-dispatcher.ts +507 -0
- package/src/judged-items.ts +263 -0
- package/src/judgment-binding.ts +349 -0
- package/src/middleware/auth.ts +3 -2
- package/src/middleware/idempotency.ts +7 -1
- package/src/openapi/generate.ts +7 -1
- package/src/openapi/operations.ts +615 -24
- package/src/openapi/schemas.ts +1157 -22
- package/src/provenance-binding.ts +42 -1
- package/src/provider-binding.ts +12 -7
- package/src/reviewer-binding.ts +10 -2
- package/src/reviewer-role.ts +35 -0
- package/src/routes/agents.ts +243 -19
- package/src/routes/approvals.ts +70 -19
- package/src/routes/blocks.ts +362 -0
- package/src/routes/conversations.ts +57 -1
- package/src/routes/cost.ts +159 -21
- package/src/routes/deployments.ts +266 -56
- package/src/routes/eval-comparison.ts +101 -0
- package/src/routes/eval-runs.ts +11 -0
- package/src/routes/flows.ts +63 -5
- package/src/routes/hierarchy-errors.ts +51 -0
- package/src/routes/identity.ts +10 -2
- package/src/routes/judged-suites.ts +363 -0
- package/src/routes/judgment-context.ts +128 -0
- package/src/routes/judgment-flow-context.ts +245 -0
- package/src/routes/judgments.ts +743 -0
- package/src/routes/orgs.ts +44 -27
- package/src/routes/policies.ts +19 -0
- package/src/routes/projects.ts +106 -95
- package/src/routes/provenance.ts +48 -1
- package/src/routes/providers.ts +5 -0
- package/src/routes/runs.ts +79 -22
- package/src/routes/scope-params.ts +35 -1
- package/src/routes/teams.ts +96 -90
- package/src/types.ts +4 -3
- package/src/webhook-endpoint-binding.ts +11 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Agent } from '@kindgi/agents';
|
|
2
|
+
import type { TenantId } from '@kindgi/types';
|
|
3
|
+
import type { UnpinnableRef } from './agent-pins.js';
|
|
4
|
+
import type { BlockRegistryBinding } from './block-binding.js';
|
|
5
|
+
/** The data-block versions an agent version pins, and the references that matched none. */
|
|
6
|
+
export interface BlockPins {
|
|
7
|
+
readonly prompts: Readonly<Record<string, string>>;
|
|
8
|
+
readonly settings: Readonly<Record<string, string>>;
|
|
9
|
+
readonly issues: readonly UnpinnableRef[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Pin the data blocks an agent references (its prompt block, settings
|
|
13
|
+
* blocks and model-settings block) when a version of it is published:
|
|
14
|
+
* each range resolves by `pickVersion` over the block's active versions,
|
|
15
|
+
* as a turn of an unpinned agent would. A reference that matches no
|
|
16
|
+
* published version, names a block of the other kind, or names model
|
|
17
|
+
* settings that aren't (`MODEL_SETTINGS_SCHEMA`) is an issue: the
|
|
18
|
+
* caller refuses the publish. So is any reference on a runtime with no
|
|
19
|
+
* block registry.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveBlockPins(blocks: BlockRegistryBinding | undefined, tenantId: TenantId, agent: Agent): Promise<BlockPins>;
|
|
22
|
+
//# sourceMappingURL=block-pins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-pins.d.ts","sourceRoot":"","sources":["../src/block-pins.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,KAAK,EAA+C,MAAM,gBAAgB,CAAC;AAEzF,OAAO,KAAK,EAAU,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,2FAA2F;AAC3F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;CAC3C;AAYD;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,oBAAoB,GAAG,SAAS,EACxC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,SAAS,CAAC,CAoCpB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
import { MODEL_SETTINGS_SCHEMA, settingsSchemaIssues } from '@kindgi/agents';
|
|
4
|
+
import { pickVersion } from '@kindgi/tools';
|
|
5
|
+
/** Page size for reading a block's versions. */
|
|
6
|
+
const VERSIONS_PAGE = 200;
|
|
7
|
+
/**
|
|
8
|
+
* Pin the data blocks an agent references (its prompt block, settings
|
|
9
|
+
* blocks and model-settings block) when a version of it is published:
|
|
10
|
+
* each range resolves by `pickVersion` over the block's active versions,
|
|
11
|
+
* as a turn of an unpinned agent would. A reference that matches no
|
|
12
|
+
* published version, names a block of the other kind, or names model
|
|
13
|
+
* settings that aren't (`MODEL_SETTINGS_SCHEMA`) is an issue: the
|
|
14
|
+
* caller refuses the publish. So is any reference on a runtime with no
|
|
15
|
+
* block registry.
|
|
16
|
+
*/
|
|
17
|
+
export async function resolveBlockPins(blocks, tenantId, agent) {
|
|
18
|
+
const prompts = {};
|
|
19
|
+
const settings = {};
|
|
20
|
+
const issues = [];
|
|
21
|
+
for (const ref of blockRefs(agent)) {
|
|
22
|
+
if (blocks === undefined) {
|
|
23
|
+
issues.push({
|
|
24
|
+
path: ref.path,
|
|
25
|
+
message: `${describe(ref)}: this runtime serves no data blocks`,
|
|
26
|
+
});
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const available = await activeBlockVersions(blocks, tenantId, ref.id);
|
|
30
|
+
const pick = pickVersion(available, ref.range);
|
|
31
|
+
if (pick.kind !== 'ok') {
|
|
32
|
+
issues.push({
|
|
33
|
+
path: ref.path,
|
|
34
|
+
message: available.length === 0
|
|
35
|
+
? `${describe(ref)} has no published version; publish the block first`
|
|
36
|
+
: `${describe(ref)} has no published version in "${ref.range}" (published: ${available.join(', ')})`,
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const block = await blocks.getVersion({ tenantId, blockId: ref.id, version: pick.version });
|
|
41
|
+
const problem = block === null
|
|
42
|
+
? `${describe(ref)} version ${pick.version} can't be read`
|
|
43
|
+
: misfit(ref, block);
|
|
44
|
+
if (problem !== undefined) {
|
|
45
|
+
issues.push({ path: ref.path, message: problem });
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
(ref.role === 'prompt' ? prompts : settings)[ref.id] = pick.version;
|
|
49
|
+
}
|
|
50
|
+
return { prompts, settings, issues };
|
|
51
|
+
}
|
|
52
|
+
function blockRefs(agent) {
|
|
53
|
+
const refs = [];
|
|
54
|
+
if (typeof agent.instructions === 'object') {
|
|
55
|
+
refs.push({
|
|
56
|
+
path: '/instructions/version',
|
|
57
|
+
id: agent.instructions.prompt,
|
|
58
|
+
range: agent.instructions.version,
|
|
59
|
+
role: 'prompt',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
for (const [i, s] of (agent.settings ?? []).entries()) {
|
|
63
|
+
refs.push({ path: `/settings/${i}/version`, id: s.id, range: s.version, role: 'settings' });
|
|
64
|
+
}
|
|
65
|
+
if (agent.modelSettings !== undefined) {
|
|
66
|
+
refs.push({
|
|
67
|
+
path: '/modelSettings/version',
|
|
68
|
+
id: agent.modelSettings.id,
|
|
69
|
+
range: agent.modelSettings.version,
|
|
70
|
+
role: 'model-settings',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return refs;
|
|
74
|
+
}
|
|
75
|
+
/** Why a block version can't serve its reference; undefined when it can. */
|
|
76
|
+
function misfit(ref, block) {
|
|
77
|
+
const wanted = ref.role === 'prompt' ? 'prompt' : 'settings';
|
|
78
|
+
if (block.kind !== wanted)
|
|
79
|
+
return `${describe(ref)} is a ${block.kind} block`;
|
|
80
|
+
if (ref.role !== 'model-settings')
|
|
81
|
+
return undefined;
|
|
82
|
+
const values = block.content.values;
|
|
83
|
+
const issues = settingsSchemaIssues(values, MODEL_SETTINGS_SCHEMA);
|
|
84
|
+
return issues.length === 0
|
|
85
|
+
? undefined
|
|
86
|
+
: `${describe(ref)} version ${block.version} isn't model settings: ${issues.map((i) => `${i.path} ${i.message}`).join('; ')}`;
|
|
87
|
+
}
|
|
88
|
+
function describe(ref) {
|
|
89
|
+
const what = ref.role === 'prompt'
|
|
90
|
+
? 'prompt'
|
|
91
|
+
: ref.role === 'model-settings'
|
|
92
|
+
? 'model-settings'
|
|
93
|
+
: 'settings';
|
|
94
|
+
return `${what} block "${ref.id}"`;
|
|
95
|
+
}
|
|
96
|
+
/** Every active version of a block, newest published first. */
|
|
97
|
+
async function activeBlockVersions(blocks, tenantId, blockId) {
|
|
98
|
+
const versions = [];
|
|
99
|
+
let cursor;
|
|
100
|
+
do {
|
|
101
|
+
const page = await blocks.listVersions({
|
|
102
|
+
tenantId,
|
|
103
|
+
blockId,
|
|
104
|
+
limit: VERSIONS_PAGE,
|
|
105
|
+
...(cursor !== undefined && { cursor }),
|
|
106
|
+
});
|
|
107
|
+
versions.push(...page.data.map((b) => b.version));
|
|
108
|
+
cursor = page.nextCursor;
|
|
109
|
+
} while (cursor !== undefined);
|
|
110
|
+
return versions;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=block-pins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-pins.js","sourceRoot":"","sources":["../src/block-pins.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EAAc,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAoB5C,gDAAgD;AAChD,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAwC,EACxC,QAAkB,EAClB,KAAY;IAEZ,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAoB,EAAE,CAAC;IACnC,KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,OAAO,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,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,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;SACxC,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC,QAAQ,MAAM,KAAK,SAAS,EAAE;IAC/B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/cost-binding.d.ts
CHANGED
|
@@ -38,9 +38,12 @@ export interface CostBinding {
|
|
|
38
38
|
getRecord(input: CostGetRecordInput): Promise<CostRecord | null>;
|
|
39
39
|
/**
|
|
40
40
|
* Multi-dimensional aggregate rollup. `groupBy` may combine any
|
|
41
|
-
* subset of `
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* subset of `COST_GROUP_DIMENSIONS`; the binding returns one group per
|
|
42
|
+
* distinct key tuple within the required `from`..`to` window, with its
|
|
43
|
+
* cost and token sums. With `limit`, a binding may return only the
|
|
44
|
+
* `limit` most expensive groups (`totalUsd` descending, ties by key)
|
|
45
|
+
* and the count before the cap in `totalGroups`; one that returns
|
|
46
|
+
* every group is capped by the route.
|
|
44
47
|
*/
|
|
45
48
|
aggregate(input: CostAggregateInput): Promise<CostAggregateResult>;
|
|
46
49
|
}
|
|
@@ -73,6 +76,8 @@ export interface CostListRecordsInput {
|
|
|
73
76
|
* uniformity: scope-aware bindings share one filter shape.
|
|
74
77
|
*/
|
|
75
78
|
readonly inherit?: boolean;
|
|
79
|
+
/** Add each record's `rawUsage`: the vendor's own usage object. */
|
|
80
|
+
readonly includeRawUsage?: boolean;
|
|
76
81
|
}
|
|
77
82
|
export interface CostRecordFilter {
|
|
78
83
|
readonly runId?: string;
|
|
@@ -86,7 +91,20 @@ export interface CostRecordFilter {
|
|
|
86
91
|
*/
|
|
87
92
|
readonly category?: string;
|
|
88
93
|
readonly providerId?: string;
|
|
94
|
+
/** The model actually called. */
|
|
95
|
+
readonly model?: string;
|
|
96
|
+
/** The exact model version the vendor reported. */
|
|
97
|
+
readonly servedModel?: string;
|
|
98
|
+
/** Every record of the run tree whose root is this run. */
|
|
99
|
+
readonly rootRunId?: string;
|
|
100
|
+
/**
|
|
101
|
+
* With `runId`: that run's records and those of every run it started,
|
|
102
|
+
* at any depth.
|
|
103
|
+
*/
|
|
104
|
+
readonly includeDescendants?: boolean;
|
|
105
|
+
/** Inclusive. */
|
|
89
106
|
readonly from?: Date;
|
|
107
|
+
/** Exclusive. */
|
|
90
108
|
readonly to?: Date;
|
|
91
109
|
}
|
|
92
110
|
export interface CostRecordPage {
|
|
@@ -96,14 +114,18 @@ export interface CostRecordPage {
|
|
|
96
114
|
export interface CostGetRecordInput {
|
|
97
115
|
readonly tenantId: TenantId;
|
|
98
116
|
readonly recordId: string;
|
|
117
|
+
/** Add the record's `rawUsage`: the vendor's own usage object. */
|
|
118
|
+
readonly includeRawUsage?: boolean;
|
|
99
119
|
}
|
|
100
120
|
/**
|
|
101
121
|
* Group dimensions the binding may aggregate over. `day` / `month` are
|
|
102
122
|
* time bucketing on `occurredAt` (UTC calendar day / month). Every call
|
|
103
123
|
* is tenant-scoped, so `tenant` always resolves to the caller's tenant
|
|
104
|
-
* id.
|
|
124
|
+
* id. `model` is the model actually called; `servedModel` the exact
|
|
125
|
+
* version the vendor reported. `orgId` is the org of the record's
|
|
126
|
+
* project (`null` for a project in no org).
|
|
105
127
|
*/
|
|
106
|
-
export type CostGroupDimension = 'agentId' | 'runId' | 'category' | 'providerId' | 'day' | 'month' | 'tenant' | 'conversationId';
|
|
128
|
+
export type CostGroupDimension = 'agentId' | 'runId' | 'category' | 'providerId' | 'day' | 'month' | 'tenant' | 'conversationId' | 'model' | 'servedModel' | 'projectId' | 'orgId' | 'rootRunId' | 'flowId';
|
|
107
129
|
export declare const COST_GROUP_DIMENSIONS: readonly CostGroupDimension[];
|
|
108
130
|
export interface CostAggregateInput {
|
|
109
131
|
readonly tenantId: TenantId;
|
|
@@ -127,7 +149,18 @@ export interface CostAggregateInput {
|
|
|
127
149
|
* shape uniformity.
|
|
128
150
|
*/
|
|
129
151
|
readonly inherit?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The most groups the caller wants (`?limit=`, 1..`COST_AGGREGATE_MAX_LIMIT`,
|
|
154
|
+
* default `COST_AGGREGATE_DEFAULT_LIMIT`): the most expensive ones. A
|
|
155
|
+
* binding may cap in its query; the window's totals stay over every
|
|
156
|
+
* record either way.
|
|
157
|
+
*/
|
|
158
|
+
readonly limit?: number;
|
|
130
159
|
}
|
|
160
|
+
/** `GET /v1/cost/aggregate`'s `?limit=` when absent. */
|
|
161
|
+
export declare const COST_AGGREGATE_DEFAULT_LIMIT = 1000;
|
|
162
|
+
/** The largest `?limit=` the aggregate takes. */
|
|
163
|
+
export declare const COST_AGGREGATE_MAX_LIMIT = 10000;
|
|
131
164
|
/**
|
|
132
165
|
* One row of the aggregate result. `key` maps every requested `groupBy`
|
|
133
166
|
* dimension to its value for this group — `null` when the underlying
|
|
@@ -139,11 +172,30 @@ export interface CostAggregateGroup {
|
|
|
139
172
|
readonly key: Readonly<Record<string, string | null>>;
|
|
140
173
|
readonly count: number;
|
|
141
174
|
readonly totalUsd: number;
|
|
175
|
+
readonly tokens: CostTokenTotals;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Token sums. `prompt` and `completion` are the totals; `cacheRead` /
|
|
179
|
+
* `cacheWrite` are parts of `prompt`, `reasoning` of `completion`
|
|
180
|
+
* (`0` where providers didn't report them).
|
|
181
|
+
*/
|
|
182
|
+
export interface CostTokenTotals {
|
|
183
|
+
readonly prompt: number;
|
|
184
|
+
readonly completion: number;
|
|
185
|
+
readonly cacheRead: number;
|
|
186
|
+
readonly cacheWrite: number;
|
|
187
|
+
readonly reasoning: number;
|
|
142
188
|
}
|
|
143
189
|
export interface CostAggregateResult {
|
|
144
190
|
readonly groups: readonly CostAggregateGroup[];
|
|
191
|
+
/**
|
|
192
|
+
* How many groups there were before a cap: set by a binding that caps
|
|
193
|
+
* (`CostAggregateInput.limit`). Absent: `groups` is every group.
|
|
194
|
+
*/
|
|
195
|
+
readonly totalGroups?: number;
|
|
145
196
|
readonly totalUsd: number;
|
|
146
197
|
readonly totalRecords: number;
|
|
198
|
+
readonly tokens: CostTokenTotals;
|
|
147
199
|
readonly timeRange: {
|
|
148
200
|
readonly from: Timestamp;
|
|
149
201
|
readonly to: Timestamp;
|
|
@@ -171,5 +223,48 @@ export interface CostRecord {
|
|
|
171
223
|
readonly occurredAt: Timestamp;
|
|
172
224
|
readonly metrics?: Readonly<Record<string, unknown>>;
|
|
173
225
|
readonly attributes?: Readonly<Record<string, unknown>>;
|
|
226
|
+
/** The call's id; its provenance node carries it too. */
|
|
227
|
+
readonly callId?: string;
|
|
228
|
+
readonly projectId?: string;
|
|
229
|
+
/** The root of the record's run tree. */
|
|
230
|
+
readonly rootRunId?: string;
|
|
231
|
+
readonly parentRunId?: string;
|
|
232
|
+
readonly agentVersion?: string;
|
|
233
|
+
/** The flow of the run tree's root. */
|
|
234
|
+
readonly flowId?: string;
|
|
235
|
+
/** The step that made the call, and the turn's step number. */
|
|
236
|
+
readonly nodeId?: string;
|
|
237
|
+
readonly step?: number;
|
|
238
|
+
/** What the call was for, beyond the turn's own model step (`guardrail-judge:<id>`). */
|
|
239
|
+
readonly purpose?: string;
|
|
240
|
+
/** The model actually called. */
|
|
241
|
+
readonly model?: string;
|
|
242
|
+
/** The exact model version the vendor reported. */
|
|
243
|
+
readonly servedModel?: string;
|
|
244
|
+
/** The router picked a fallback provider. */
|
|
245
|
+
readonly fallback?: boolean;
|
|
246
|
+
/** `ok`: the provider answered. `failed`: the call threw. */
|
|
247
|
+
readonly status?: 'ok' | 'failed';
|
|
248
|
+
readonly usage?: {
|
|
249
|
+
readonly promptTokens: number;
|
|
250
|
+
readonly completionTokens: number;
|
|
251
|
+
readonly cacheReadTokens?: number;
|
|
252
|
+
readonly cacheWriteTokens?: number;
|
|
253
|
+
readonly reasoningTokens?: number;
|
|
254
|
+
};
|
|
255
|
+
readonly durationMs?: number;
|
|
256
|
+
readonly finishReason?: string;
|
|
257
|
+
readonly providerRequestId?: string;
|
|
258
|
+
/** HTTP attempts, the client's retries included. */
|
|
259
|
+
readonly attempts?: number;
|
|
260
|
+
readonly error?: {
|
|
261
|
+
readonly message: string;
|
|
262
|
+
};
|
|
263
|
+
/** The vendor's own usage object (only when asked for: `include=rawUsage`). */
|
|
264
|
+
readonly rawUsage?: {
|
|
265
|
+
readonly provider: string;
|
|
266
|
+
readonly model: string;
|
|
267
|
+
readonly usage: Readonly<Record<string, unknown>>;
|
|
268
|
+
};
|
|
174
269
|
}
|
|
175
270
|
//# sourceMappingURL=cost-binding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-binding.d.ts","sourceRoot":"","sources":["../src/cost-binding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAClE;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACjE
|
|
1
|
+
{"version":3,"file":"cost-binding.d.ts","sourceRoot":"","sources":["../src/cost-binding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,M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
'conversationId',
|
|
12
|
+
'model',
|
|
13
|
+
'servedModel',
|
|
14
|
+
'projectId',
|
|
15
|
+
'orgId',
|
|
16
|
+
'rootRunId',
|
|
17
|
+
'flowId',
|
|
12
18
|
];
|
|
19
|
+
/** `GET /v1/cost/aggregate`'s `?limit=` when absent. */
|
|
20
|
+
export const COST_AGGREGATE_DEFAULT_LIMIT = 1000;
|
|
21
|
+
/** The largest `?limit=` the aggregate takes. */
|
|
22
|
+
export const COST_AGGREGATE_MAX_LIMIT = 10_000;
|
|
13
23
|
//# sourceMappingURL=cost-binding.js.map
|
package/dist/cost-binding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-binding.js","sourceRoot":"","sources":["../src/cost-binding.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;
|
|
1
|
+
{"version":3,"file":"cost-binding.js","sourceRoot":"","sources":["../src/cost-binding.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAgKjC,MAAM,CAAC,MAAM,qBAAqB,GAAkC;IAClE,SAAS;IACT,OAAO;IACP,UAAU;IACV,YAAY;IACZ,KAAK;IACL,OAAO;IACP,QAAQ;IACR,gBAAgB;IAChB,OAAO;IACP,aAAa;IACb,WAAW;IACX,OAAO;IACP,WAAW;IACX,QAAQ;CACT,CAAC;AAiCF,wDAAwD;AACxD,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,iDAAiD;AACjD,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type PinChange, type PinSet } from '@kindgi/agents';
|
|
2
|
+
import type { VersionDerivation, VersionDerivationReason } from '@kindgi/types';
|
|
3
|
+
/** A version a deploy registers with pins: an agent's or a flow's. */
|
|
4
|
+
export interface PinnedDefinition {
|
|
5
|
+
readonly version: string;
|
|
6
|
+
readonly pins?: PinSet;
|
|
7
|
+
readonly pinsDigest?: string;
|
|
8
|
+
readonly derivedFrom?: VersionDerivation;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* How a deploy registered one of its agents or flows, given its pins.
|
|
12
|
+
* A deploy never keeps a version's old pins and never refuses a
|
|
13
|
+
* routine deploy:
|
|
14
|
+
*
|
|
15
|
+
* - `registered`: the definition's version was free, and is now
|
|
16
|
+
* registered with these pins;
|
|
17
|
+
* - `unchanged`: it's registered with the same definition and pins (or
|
|
18
|
+
* its project is gone, which a deploy has always left as it is);
|
|
19
|
+
* - `reused`: an earlier deploy already registered this definition and
|
|
20
|
+
* these pins under another number (`version`), so a redeploy changes
|
|
21
|
+
* nothing;
|
|
22
|
+
* - `renumbered`: the definition's version is registered with other
|
|
23
|
+
* pins or other content, and versions never change, so this deploy
|
|
24
|
+
* registered the next free version in its line (`nextVersion`).
|
|
25
|
+
*/
|
|
26
|
+
export type DeployedVersionOutcome = {
|
|
27
|
+
readonly kind: 'registered' | 'unchanged';
|
|
28
|
+
readonly version: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'reused' | 'renumbered';
|
|
31
|
+
readonly version: string;
|
|
32
|
+
readonly reason: VersionDerivationReason;
|
|
33
|
+
readonly pinChanges?: readonly PinChange[];
|
|
34
|
+
};
|
|
35
|
+
/** What registering one version did: stored it, found the number taken, or left it (no project). */
|
|
36
|
+
export type PublishOutcome = 'ok' | 'taken' | 'skipped';
|
|
37
|
+
export interface DeployVersionInput<T extends PinnedDefinition> {
|
|
38
|
+
/** Names the definition in an error, e.g. `agent "acme.matcher"`. */
|
|
39
|
+
readonly label: string;
|
|
40
|
+
/** The definition as the pack has it, with no pins. */
|
|
41
|
+
readonly definition: T;
|
|
42
|
+
readonly pins: PinSet;
|
|
43
|
+
readonly pinsDigest: string;
|
|
44
|
+
/** Every active version registered under the definition's id. */
|
|
45
|
+
readonly existing: readonly T[];
|
|
46
|
+
/** Register one version. */
|
|
47
|
+
readonly publish: (version: T) => Promise<PublishOutcome>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Register a deployed agent or flow with its pins (see
|
|
51
|
+
* `DeployedVersionOutcome`): one rule for both, so they can't drift
|
|
52
|
+
* apart. Each definition is registered at most once per deploy, and a
|
|
53
|
+
* new version derives from the definition's version only, never from a
|
|
54
|
+
* version the same deploy created, so a change cascading from a tool
|
|
55
|
+
* through an agent into a flow ends within the one deploy.
|
|
56
|
+
*/
|
|
57
|
+
export declare function deployVersion<T extends PinnedDefinition>(input: DeployVersionInput<T>): Promise<DeployedVersionOutcome>;
|
|
58
|
+
//# sourceMappingURL=deploy-versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy-versions.d.ts","sourceRoot":"","sources":["../src/deploy-versions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAc,MAAM,gBAAgB,CAAC;AAGzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAEhF,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvE;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CAC5C,CAAC;AAEN,oGAAoG;AACpG,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS,CAAC;AAExD,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,gBAAgB;IAC5D,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;IAChC,4BAA4B;IAC5B,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CAC3D;AAKD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,gBAAgB,EAC5D,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,sBAAsB,CAAC,CAsCjC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
import { pinChanges } from '@kindgi/agents';
|
|
4
|
+
import { canonicalize } from '@kindgi/schema';
|
|
5
|
+
import { nextVersion } from '@kindgi/tools';
|
|
6
|
+
/** How many versions after the definition's a deploy tries before it gives up. */
|
|
7
|
+
const MAX_RENUMBER = 100;
|
|
8
|
+
/**
|
|
9
|
+
* Register a deployed agent or flow with its pins (see
|
|
10
|
+
* `DeployedVersionOutcome`): one rule for both, so they can't drift
|
|
11
|
+
* apart. Each definition is registered at most once per deploy, and a
|
|
12
|
+
* new version derives from the definition's version only, never from a
|
|
13
|
+
* version the same deploy created, so a change cascading from a tool
|
|
14
|
+
* through an agent into a flow ends within the one deploy.
|
|
15
|
+
*/
|
|
16
|
+
export async function deployVersion(input) {
|
|
17
|
+
const { definition, pins, pinsDigest, existing } = input;
|
|
18
|
+
const authored = definition.version;
|
|
19
|
+
const key = definitionKey(definition);
|
|
20
|
+
const same = (v) => definitionKey(v) === key && v.pinsDigest === pinsDigest;
|
|
21
|
+
const atAuthored = existing.find((v) => v.version === authored);
|
|
22
|
+
if (atAuthored !== undefined && same(atAuthored))
|
|
23
|
+
return { kind: 'unchanged', version: authored };
|
|
24
|
+
if (atAuthored === undefined) {
|
|
25
|
+
const outcome = await input.publish({ ...definition, pins, pinsDigest });
|
|
26
|
+
if (outcome !== 'taken') {
|
|
27
|
+
return { kind: outcome === 'ok' ? 'registered' : 'unchanged', version: authored };
|
|
28
|
+
}
|
|
29
|
+
// Taken with no active version: an unregistered version holds the
|
|
30
|
+
// number. Register the next one.
|
|
31
|
+
}
|
|
32
|
+
const reason = derivationReason(atAuthored, key);
|
|
33
|
+
const changes = reason === 'pins-changed' ? { pinChanges: pinChanges(atAuthored?.pins, pins) } : {};
|
|
34
|
+
const earlier = existing.find(same);
|
|
35
|
+
if (earlier !== undefined) {
|
|
36
|
+
return {
|
|
37
|
+
kind: 'reused',
|
|
38
|
+
version: earlier.version,
|
|
39
|
+
// An expert's edit reused by a deploy reports the deploy's own reason.
|
|
40
|
+
reason: earlier.derivedFrom !== undefined && earlier.derivedFrom.reason !== 'edited'
|
|
41
|
+
? earlier.derivedFrom.reason
|
|
42
|
+
: reason,
|
|
43
|
+
...changes,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const taken = new Set(existing.map((v) => v.version));
|
|
47
|
+
const version = await registerNextFree(input, reason, taken);
|
|
48
|
+
return version === undefined
|
|
49
|
+
? { kind: 'unchanged', version: authored }
|
|
50
|
+
: { kind: 'renumbered', version, reason, ...changes };
|
|
51
|
+
}
|
|
52
|
+
/** Why the definition's version can't be registered as it is. */
|
|
53
|
+
function derivationReason(atAuthored, key) {
|
|
54
|
+
if (atAuthored === undefined || definitionKey(atAuthored) !== key)
|
|
55
|
+
return 'version-taken';
|
|
56
|
+
return atAuthored.pins === undefined ? 'unpinned' : 'pins-changed';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Register the definition with its pins under the first free version
|
|
60
|
+
* after its own (`nextVersion`), recording where it came from.
|
|
61
|
+
* `undefined` when it was left as it is (its project is gone).
|
|
62
|
+
*/
|
|
63
|
+
async function registerNextFree(input, reason, taken) {
|
|
64
|
+
const { definition, pins, pinsDigest } = input;
|
|
65
|
+
const authored = definition.version;
|
|
66
|
+
let candidate = nextVersion(authored);
|
|
67
|
+
for (let tries = 0; candidate !== undefined && tries < MAX_RENUMBER; tries++) {
|
|
68
|
+
if (!taken.has(candidate)) {
|
|
69
|
+
const outcome = await input.publish({
|
|
70
|
+
...definition,
|
|
71
|
+
version: candidate,
|
|
72
|
+
pins,
|
|
73
|
+
pinsDigest,
|
|
74
|
+
derivedFrom: { version: authored, reason },
|
|
75
|
+
});
|
|
76
|
+
if (outcome === 'ok')
|
|
77
|
+
return candidate;
|
|
78
|
+
if (outcome === 'skipped')
|
|
79
|
+
return undefined;
|
|
80
|
+
// Taken: an unregistered version holds this one too.
|
|
81
|
+
}
|
|
82
|
+
candidate = nextVersion(candidate);
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`${input.label}: no free version after ${authored} to register its new pins under`);
|
|
85
|
+
}
|
|
86
|
+
/** A definition: everything but its version and what the runtime sets. */
|
|
87
|
+
function definitionKey(definition) {
|
|
88
|
+
const { version: _v, pins: _p, pinsDigest: _d, derivedFrom: _f, ...rest } = definition;
|
|
89
|
+
return canonicalize(rest);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=deploy-versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy-versions.js","sourceRoot":"","sources":["../src/deploy-versions.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OA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AG,UAAU,CAAC;IACvF,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PinChange } from '@kindgi/agents';
|
|
2
|
+
import type { Cursor, SigningKeyId, TenantId, VersionDerivationReason } from '@kindgi/types';
|
|
2
3
|
/**
|
|
3
4
|
* Caller-plugged surface for the deployment ledger — the audit anchor
|
|
4
5
|
* row written by `POST /v1/deployments`. Mirrors the
|
|
@@ -118,11 +119,31 @@ export interface DeployedPrimitive {
|
|
|
118
119
|
readonly id: string;
|
|
119
120
|
readonly version?: string;
|
|
120
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* An agent or flow a deployment shipped, under the version it's
|
|
124
|
+
* registered as. A deploy registers one under another version than its
|
|
125
|
+
* definition's when that version is registered already with other pins
|
|
126
|
+
* or content (versions never change); then `authoredVersion` is the
|
|
127
|
+
* definition's and `reason` says why.
|
|
128
|
+
*/
|
|
129
|
+
export interface DeployedVersion extends DeployedPrimitive {
|
|
130
|
+
/** The version the agent's definition names, when it differs from `version`. */
|
|
131
|
+
readonly authoredVersion?: string;
|
|
132
|
+
readonly reason?: VersionDerivationReason;
|
|
133
|
+
/** `true`: this deploy registered `version`; `false`: an earlier deploy did. */
|
|
134
|
+
readonly newVersion?: boolean;
|
|
135
|
+
/** For `pins-changed`: the pins that differ from `authoredVersion`'s. */
|
|
136
|
+
readonly pinChanges?: readonly PinChange[];
|
|
137
|
+
}
|
|
138
|
+
/** An agent a deployment shipped (`DeployedVersion`). */
|
|
139
|
+
export type DeployedAgent = DeployedVersion;
|
|
140
|
+
/** A flow a deployment shipped (`DeployedVersion`). */
|
|
141
|
+
export type DeployedFlow = DeployedVersion;
|
|
121
142
|
export interface DeploymentContents {
|
|
122
143
|
readonly tools: readonly DeployedPrimitive[];
|
|
123
144
|
readonly guardrails: readonly DeployedPrimitive[];
|
|
124
|
-
readonly agents: readonly
|
|
125
|
-
readonly flows: readonly
|
|
145
|
+
readonly agents: readonly DeployedAgent[];
|
|
146
|
+
readonly flows: readonly DeployedFlow[];
|
|
126
147
|
}
|
|
127
148
|
export interface DeploymentPrimitiveCounts {
|
|
128
149
|
readonly tools: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-binding.d.ts","sourceRoot":"","sources":["../src/deployment-binding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"deployment-binding.d.ts","sourceRoot":"","sources":["../src/deployment-binding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC7E;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAC3D;;;;;OAKG;IACH,gBAAgB,CAAC,KAAK,EAAE,+BAA+B,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACrF;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC3D;AAID;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,E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AkE;IAClE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIN,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAID,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,CAAC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Agent, type AgentId } from '@kindgi/agents';
|
|
2
|
+
import type { TupleEnqueueHook } from '@kindgi/authz';
|
|
3
|
+
import type { ProjectId, TenantId } from '@kindgi/types';
|
|
4
|
+
import type { AgentRegistryBinding } from './agent-binding.js';
|
|
5
|
+
import type { BlockRegistryBinding } from './block-binding.js';
|
|
6
|
+
/** Which data-block pins to swap, by kind then block id → exact version. */
|
|
7
|
+
export interface PinSwaps {
|
|
8
|
+
readonly prompts?: Readonly<Record<string, string>>;
|
|
9
|
+
readonly settings?: Readonly<Record<string, string>>;
|
|
10
|
+
}
|
|
11
|
+
export interface DeriveAgentVersionInput {
|
|
12
|
+
readonly agents: AgentRegistryBinding;
|
|
13
|
+
readonly blocks: BlockRegistryBinding | undefined;
|
|
14
|
+
readonly tenantId: TenantId;
|
|
15
|
+
readonly agentId: AgentId;
|
|
16
|
+
/** The version to derive from: it must be pinned. */
|
|
17
|
+
readonly from: string;
|
|
18
|
+
readonly swaps: PinSwaps;
|
|
19
|
+
/** A short label for the new version. */
|
|
20
|
+
readonly label?: string;
|
|
21
|
+
/** Who derived it (`user:<id>`). */
|
|
22
|
+
readonly by?: string;
|
|
23
|
+
/** The project, when the store doesn't record one on the version. */
|
|
24
|
+
readonly projectId?: ProjectId;
|
|
25
|
+
/** The authorization tuples for the new version, in the project it lands in. */
|
|
26
|
+
readonly tuplesFor: (projectId: ProjectId) => TupleEnqueueHook;
|
|
27
|
+
}
|
|
28
|
+
export interface SwapIssue {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly message: string;
|
|
31
|
+
}
|
|
32
|
+
export type DeriveAgentVersionOutcome = {
|
|
33
|
+
readonly kind: 'ok';
|
|
34
|
+
readonly agent: Agent;
|
|
35
|
+
} | {
|
|
36
|
+
readonly kind: 'not-found';
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'unpinned';
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: 'invalid';
|
|
41
|
+
readonly issues: readonly SwapIssue[];
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: 'no-project';
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'project-not-found';
|
|
46
|
+
readonly projectId: ProjectId;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Derive a new agent version from a pinned one with some data-block
|
|
50
|
+
* pins swapped: an expert's edit (a new prompt or settings version)
|
|
51
|
+
* reaching an agent without a code change. The new version is the old
|
|
52
|
+
* one's bag with those pins swapped (`derivedFrom: { version, reason:
|
|
53
|
+
* 'edited', label, by }`), numbered the next free patch after the
|
|
54
|
+
* agent's highest version (versions never change).
|
|
55
|
+
*
|
|
56
|
+
* Only data-block pins swap: a swap must name a block the version
|
|
57
|
+
* already references (adding one is a code change), at a published,
|
|
58
|
+
* active version of the right kind (and, for the model-settings block,
|
|
59
|
+
* model settings). Tool pins come from code.
|
|
60
|
+
*/
|
|
61
|
+
export declare function deriveAgentVersion(input: DeriveAgentVersionInput): Promise<DeriveAgentVersionOutcome>;
|
|
62
|
+
/**
|
|
63
|
+
* The first version after `after` that no version of the agent holds,
|
|
64
|
+
* active or unregistered (versions never change): what a refused
|
|
65
|
+
* publish of a taken number suggests, by the deploy rule's numbering.
|
|
66
|
+
* `undefined` when none is free within the tries.
|
|
67
|
+
*/
|
|
68
|
+
export declare function nextFreeAgentVersion(agents: AgentRegistryBinding, tenantId: TenantId, agentId: AgentId, after: string): Promise<string | undefined>;
|
|
69
|
+
//# sourceMappingURL=derive-agent-version.d.ts.map
|