@getcliqio/cliq-sdk 0.0.0-stage → 1.15.32
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/README.md +28 -2
- package/dist/agent_api.d.ts +39 -0
- package/dist/agent_api.d.ts.map +1 -0
- package/dist/agent_api.js +105 -0
- package/dist/agent_api.js.map +1 -0
- package/dist/agent_manifest.d.ts +162 -0
- package/dist/agent_manifest.d.ts.map +1 -0
- package/dist/agent_manifest.js +242 -0
- package/dist/agent_manifest.js.map +1 -0
- package/dist/agent_payloads.d.ts +103 -0
- package/dist/agent_payloads.d.ts.map +1 -0
- package/dist/agent_payloads.js +56 -0
- package/dist/agent_payloads.js.map +1 -0
- package/dist/agents/base_agent.d.ts +113 -0
- package/dist/agents/base_agent.d.ts.map +1 -0
- package/dist/agents/base_agent.js +413 -0
- package/dist/agents/base_agent.js.map +1 -0
- package/dist/agents/cli_agent.d.ts +98 -0
- package/dist/agents/cli_agent.d.ts.map +1 -0
- package/dist/agents/cli_agent.js +303 -0
- package/dist/agents/cli_agent.js.map +1 -0
- package/dist/agents/cli_rehydrate.d.ts +29 -0
- package/dist/agents/cli_rehydrate.d.ts.map +1 -0
- package/dist/agents/cli_rehydrate.js +32 -0
- package/dist/agents/cli_rehydrate.js.map +1 -0
- package/dist/agents/connector_agent.d.ts +20 -0
- package/dist/agents/connector_agent.d.ts.map +1 -0
- package/dist/agents/connector_agent.js +110 -0
- package/dist/agents/connector_agent.js.map +1 -0
- package/dist/agents/event_artifacts.d.ts +33 -0
- package/dist/agents/event_artifacts.d.ts.map +1 -0
- package/dist/agents/event_artifacts.js +73 -0
- package/dist/agents/event_artifacts.js.map +1 -0
- package/dist/agents/gate_agent.d.ts +40 -0
- package/dist/agents/gate_agent.d.ts.map +1 -0
- package/dist/agents/gate_agent.js +121 -0
- package/dist/agents/gate_agent.js.map +1 -0
- package/dist/agents/index.d.ts +32 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +26 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/llm_agent.d.ts +109 -0
- package/dist/agents/llm_agent.d.ts.map +1 -0
- package/dist/agents/llm_agent.js +285 -0
- package/dist/agents/llm_agent.js.map +1 -0
- package/dist/agents/llm_contract.d.ts +7 -0
- package/dist/agents/llm_contract.d.ts.map +1 -0
- package/dist/agents/llm_contract.js +7 -0
- package/dist/agents/llm_contract.js.map +1 -0
- package/dist/agents/standard_agent.d.ts +15 -0
- package/dist/agents/standard_agent.d.ts.map +1 -0
- package/dist/agents/standard_agent.js +34 -0
- package/dist/agents/standard_agent.js.map +1 -0
- package/dist/agents/turn_result.d.ts +67 -0
- package/dist/agents/turn_result.d.ts.map +1 -0
- package/dist/agents/turn_result.js +81 -0
- package/dist/agents/turn_result.js.map +1 -0
- package/dist/agents/types.d.ts +314 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +20 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/builtin_teams/hello_hug.d.ts +9 -0
- package/dist/builtin_teams/hello_hug.d.ts.map +1 -0
- package/dist/builtin_teams/hello_hug.js +68 -0
- package/dist/builtin_teams/hello_hug.js.map +1 -0
- package/dist/builtin_teams/hello_world.d.ts +8 -0
- package/dist/builtin_teams/hello_world.d.ts.map +1 -0
- package/dist/builtin_teams/hello_world.js +65 -0
- package/dist/builtin_teams/hello_world.js.map +1 -0
- package/dist/builtin_teams/hug_example.d.ts +10 -0
- package/dist/builtin_teams/hug_example.d.ts.map +1 -0
- package/dist/builtin_teams/hug_example.js +94 -0
- package/dist/builtin_teams/hug_example.js.map +1 -0
- package/dist/builtin_teams/index.d.ts +12 -0
- package/dist/builtin_teams/index.d.ts.map +1 -0
- package/dist/builtin_teams/index.js +18 -0
- package/dist/builtin_teams/index.js.map +1 -0
- package/dist/builtin_teams/types.d.ts +29 -0
- package/dist/builtin_teams/types.d.ts.map +1 -0
- package/dist/builtin_teams/types.js +3 -0
- package/dist/builtin_teams/types.js.map +1 -0
- package/dist/core_api_client.d.ts +48 -0
- package/dist/core_api_client.d.ts.map +1 -0
- package/dist/core_api_client.js +132 -0
- package/dist/core_api_client.js.map +1 -0
- package/dist/daemon_wire.d.ts +122 -0
- package/dist/daemon_wire.d.ts.map +1 -0
- package/dist/daemon_wire.js +105 -0
- package/dist/daemon_wire.js.map +1 -0
- package/dist/events/catalog.d.ts +40 -0
- package/dist/events/catalog.d.ts.map +1 -0
- package/dist/events/catalog.js +76 -0
- package/dist/events/catalog.js.map +1 -0
- package/dist/http_daemon_client.d.ts +136 -0
- package/dist/http_daemon_client.d.ts.map +1 -0
- package/dist/http_daemon_client.js +192 -0
- package/dist/http_daemon_client.js.map +1 -0
- package/dist/hug/ask.d.ts +160 -0
- package/dist/hug/ask.d.ts.map +1 -0
- package/dist/hug/ask.js +318 -0
- package/dist/hug/ask.js.map +1 -0
- package/dist/hug/attach.d.ts +60 -0
- package/dist/hug/attach.d.ts.map +1 -0
- package/dist/hug/attach.js +103 -0
- package/dist/hug/attach.js.map +1 -0
- package/dist/hug/bridge/index.d.ts +16 -0
- package/dist/hug/bridge/index.d.ts.map +1 -0
- package/dist/hug/bridge/index.js +13 -0
- package/dist/hug/bridge/index.js.map +1 -0
- package/dist/hug/bridge/messages.d.ts +559 -0
- package/dist/hug/bridge/messages.d.ts.map +1 -0
- package/dist/hug/bridge/messages.js +165 -0
- package/dist/hug/bridge/messages.js.map +1 -0
- package/dist/hug/client.d.ts +70 -0
- package/dist/hug/client.d.ts.map +1 -0
- package/dist/hug/client.js +144 -0
- package/dist/hug/client.js.map +1 -0
- package/dist/hug/context.d.ts +54 -0
- package/dist/hug/context.d.ts.map +1 -0
- package/dist/hug/context.js +27 -0
- package/dist/hug/context.js.map +1 -0
- package/dist/hug/define.d.ts +116 -0
- package/dist/hug/define.d.ts.map +1 -0
- package/dist/hug/define.js +119 -0
- package/dist/hug/define.js.map +1 -0
- package/dist/hug/definitions/approval.d.ts +216 -0
- package/dist/hug/definitions/approval.d.ts.map +1 -0
- package/dist/hug/definitions/approval.js +50 -0
- package/dist/hug/definitions/approval.js.map +1 -0
- package/dist/hug/definitions/common.d.ts +122 -0
- package/dist/hug/definitions/common.d.ts.map +1 -0
- package/dist/hug/definitions/common.js +70 -0
- package/dist/hug/definitions/common.js.map +1 -0
- package/dist/hug/definitions/form.d.ts +197 -0
- package/dist/hug/definitions/form.d.ts.map +1 -0
- package/dist/hug/definitions/form.js +29 -0
- package/dist/hug/definitions/form.js.map +1 -0
- package/dist/hug/definitions/index.d.ts +10 -0
- package/dist/hug/definitions/index.d.ts.map +1 -0
- package/dist/hug/definitions/index.js +8 -0
- package/dist/hug/definitions/index.js.map +1 -0
- package/dist/hug/errors.d.ts +30 -0
- package/dist/hug/errors.d.ts.map +1 -0
- package/dist/hug/errors.js +46 -0
- package/dist/hug/errors.js.map +1 -0
- package/dist/hug/file_checks.d.ts +41 -0
- package/dist/hug/file_checks.d.ts.map +1 -0
- package/dist/hug/file_checks.js +105 -0
- package/dist/hug/file_checks.js.map +1 -0
- package/dist/hug/files.d.ts +137 -0
- package/dist/hug/files.d.ts.map +1 -0
- package/dist/hug/files.js +283 -0
- package/dist/hug/files.js.map +1 -0
- package/dist/hug/hug_bundle.d.ts +70 -0
- package/dist/hug/hug_bundle.d.ts.map +1 -0
- package/dist/hug/hug_bundle.js +299 -0
- package/dist/hug/hug_bundle.js.map +1 -0
- package/dist/hug/hug_catalog.d.ts +38 -0
- package/dist/hug/hug_catalog.d.ts.map +1 -0
- package/dist/hug/hug_catalog.js +67 -0
- package/dist/hug/hug_catalog.js.map +1 -0
- package/dist/hug/hug_definitions.d.ts +32 -0
- package/dist/hug/hug_definitions.d.ts.map +1 -0
- package/dist/hug/hug_definitions.js +74 -0
- package/dist/hug/hug_definitions.js.map +1 -0
- package/dist/hug/index.d.ts +37 -0
- package/dist/hug/index.d.ts.map +1 -0
- package/dist/hug/index.js +23 -0
- package/dist/hug/index.js.map +1 -0
- package/dist/hug/llm.d.ts +106 -0
- package/dist/hug/llm.d.ts.map +1 -0
- package/dist/hug/llm.js +250 -0
- package/dist/hug/llm.js.map +1 -0
- package/dist/hug/policies.d.ts +65 -0
- package/dist/hug/policies.d.ts.map +1 -0
- package/dist/hug/policies.js +80 -0
- package/dist/hug/policies.js.map +1 -0
- package/dist/hug/problems.d.ts +35 -0
- package/dist/hug/problems.d.ts.map +1 -0
- package/dist/hug/problems.js +53 -0
- package/dist/hug/problems.js.map +1 -0
- package/dist/hug/requested_inputs.d.ts +190 -0
- package/dist/hug/requested_inputs.d.ts.map +1 -0
- package/dist/hug/requested_inputs.js +220 -0
- package/dist/hug/requested_inputs.js.map +1 -0
- package/dist/hug/schema_for_inputs.d.ts +20 -0
- package/dist/hug/schema_for_inputs.d.ts.map +1 -0
- package/dist/hug/schema_for_inputs.js +95 -0
- package/dist/hug/schema_for_inputs.js.map +1 -0
- package/dist/hug/session.d.ts +113 -0
- package/dist/hug/session.d.ts.map +1 -0
- package/dist/hug/session.js +210 -0
- package/dist/hug/session.js.map +1 -0
- package/dist/hug/types.d.ts +141 -0
- package/dist/hug/types.d.ts.map +1 -0
- package/dist/hug/types.js +80 -0
- package/dist/hug/types.js.map +1 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.d.ts +172 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +306 -0
- package/dist/logging.js.map +1 -0
- package/dist/mcp.d.ts +119 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +259 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcp_client.d.ts +145 -0
- package/dist/mcp_client.d.ts.map +1 -0
- package/dist/mcp_client.js +374 -0
- package/dist/mcp_client.js.map +1 -0
- package/dist/paths.d.ts +20 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +20 -0
- package/dist/paths.js.map +1 -0
- package/dist/protocol/factory.d.ts +32 -0
- package/dist/protocol/factory.d.ts.map +1 -0
- package/dist/protocol/factory.js +31 -0
- package/dist/protocol/factory.js.map +1 -0
- package/dist/protocol/framing.d.ts +35 -0
- package/dist/protocol/framing.d.ts.map +1 -0
- package/dist/protocol/framing.js +73 -0
- package/dist/protocol/framing.js.map +1 -0
- package/dist/protocol/index.d.ts +13 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +13 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/types/agent.d.ts +42 -0
- package/dist/protocol/types/agent.d.ts.map +1 -0
- package/dist/protocol/types/agent.js +9 -0
- package/dist/protocol/types/agent.js.map +1 -0
- package/dist/protocol/types/cliq_core.d.ts +79 -0
- package/dist/protocol/types/cliq_core.d.ts.map +1 -0
- package/dist/protocol/types/cliq_core.js +17 -0
- package/dist/protocol/types/cliq_core.js.map +1 -0
- package/dist/protocol/types/foundations.d.ts +41 -0
- package/dist/protocol/types/foundations.d.ts.map +1 -0
- package/dist/protocol/types/foundations.js +10 -0
- package/dist/protocol/types/foundations.js.map +1 -0
- package/dist/protocol/types/index.d.ts +32 -0
- package/dist/protocol/types/index.d.ts.map +1 -0
- package/dist/protocol/types/index.js +27 -0
- package/dist/protocol/types/index.js.map +1 -0
- package/dist/protocol/types/messages.d.ts +827 -0
- package/dist/protocol/types/messages.d.ts.map +1 -0
- package/dist/protocol/types/messages.js +117 -0
- package/dist/protocol/types/messages.js.map +1 -0
- package/dist/protocol/types/pipeline.d.ts +122 -0
- package/dist/protocol/types/pipeline.d.ts.map +1 -0
- package/dist/protocol/types/pipeline.js +16 -0
- package/dist/protocol/types/pipeline.js.map +1 -0
- package/dist/protocol/types/schemas.d.ts +814 -0
- package/dist/protocol/types/schemas.d.ts.map +1 -0
- package/dist/protocol/types/schemas.js +772 -0
- package/dist/protocol/types/schemas.js.map +1 -0
- package/dist/protocol/types/team.d.ts +42 -0
- package/dist/protocol/types/team.d.ts.map +1 -0
- package/dist/protocol/types/team.js +15 -0
- package/dist/protocol/types/team.js.map +1 -0
- package/dist/protocol/types/workspace.d.ts +46 -0
- package/dist/protocol/types/workspace.d.ts.map +1 -0
- package/dist/protocol/types/workspace.js +9 -0
- package/dist/protocol/types/workspace.js.map +1 -0
- package/dist/settings_keys.d.ts +12 -0
- package/dist/settings_keys.d.ts.map +1 -0
- package/dist/settings_keys.js +35 -0
- package/dist/settings_keys.js.map +1 -0
- package/dist/tcp/client.d.ts +15 -0
- package/dist/tcp/client.d.ts.map +1 -0
- package/dist/tcp/client.js +28 -0
- package/dist/tcp/client.js.map +1 -0
- package/dist/tcp/connection.d.ts +79 -0
- package/dist/tcp/connection.d.ts.map +1 -0
- package/dist/tcp/connection.js +153 -0
- package/dist/tcp/connection.js.map +1 -0
- package/dist/tcp/index.d.ts +10 -0
- package/dist/tcp/index.d.ts.map +1 -0
- package/dist/tcp/index.js +7 -0
- package/dist/tcp/index.js.map +1 -0
- package/dist/tcp/server.d.ts +31 -0
- package/dist/tcp/server.d.ts.map +1 -0
- package/dist/tcp/server.js +54 -0
- package/dist/tcp/server.js.map +1 -0
- package/dist/team/bundle.d.ts +88 -0
- package/dist/team/bundle.d.ts.map +1 -0
- package/dist/team/bundle.js +214 -0
- package/dist/team/bundle.js.map +1 -0
- package/dist/team/identity.d.ts +31 -0
- package/dist/team/identity.d.ts.map +1 -0
- package/dist/team/identity.js +83 -0
- package/dist/team/identity.js.map +1 -0
- package/dist/team/index.d.ts +13 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/index.js +8 -0
- package/dist/team/index.js.map +1 -0
- package/dist/team/lint_bundle.d.ts +16 -0
- package/dist/team/lint_bundle.d.ts.map +1 -0
- package/dist/team/lint_bundle.js +35 -0
- package/dist/team/lint_bundle.js.map +1 -0
- package/dist/team/ref.d.ts +48 -0
- package/dist/team/ref.d.ts.map +1 -0
- package/dist/team/ref.js +70 -0
- package/dist/team/ref.js.map +1 -0
- package/dist/team/roles.d.ts +22 -0
- package/dist/team/roles.d.ts.map +1 -0
- package/dist/team/roles.js +33 -0
- package/dist/team/roles.js.map +1 -0
- package/dist/team/tree.d.ts +101 -0
- package/dist/team/tree.d.ts.map +1 -0
- package/dist/team/tree.js +125 -0
- package/dist/team/tree.js.map +1 -0
- package/dist/team_lint.d.ts +57 -0
- package/dist/team_lint.d.ts.map +1 -0
- package/dist/team_lint.js +277 -0
- package/dist/team_lint.js.map +1 -0
- package/dist/telemetry/stream_json_usage.d.ts +39 -0
- package/dist/telemetry/stream_json_usage.d.ts.map +1 -0
- package/dist/telemetry/stream_json_usage.js +139 -0
- package/dist/telemetry/stream_json_usage.js.map +1 -0
- package/dist/telemetry/usage.d.ts +288 -0
- package/dist/telemetry/usage.d.ts.map +1 -0
- package/dist/telemetry/usage.js +421 -0
- package/dist/telemetry/usage.js.map +1 -0
- package/dist/utils/duration.d.ts +11 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +22 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/redact.d.ts +26 -0
- package/dist/utils/redact.d.ts.map +1 -0
- package/dist/utils/redact.js +52 -0
- package/dist/utils/redact.js.map +1 -0
- package/dist/utils/url.d.ts +6 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +11 -0
- package/dist/utils/url.js.map +1 -0
- package/package.json +72 -5
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UsageRecord — the common structure every agent reports (or has
|
|
3
|
+
* synthesized on its behalf) so we can aggregate telemetry across
|
|
4
|
+
* LLM, connector, shell, gate, and builder agents in one query.
|
|
5
|
+
*
|
|
6
|
+
* The record is versioned (`version: 1`) and has a *closed* core of
|
|
7
|
+
* aggregable fields plus a namespaced `extras` bag for provider- /
|
|
8
|
+
* agent-specific facts. Dashboards SUM the closed core; they SEARCH
|
|
9
|
+
* the extras.
|
|
10
|
+
*
|
|
11
|
+
* The record is emitted by the SDK via `report_usage(...)` (which
|
|
12
|
+
* POSTs an `event_type: 'usage'` to the daemon's `/v1/runs/events`)
|
|
13
|
+
* and merged onto the still-open `agent.execute` OTEL span by the
|
|
14
|
+
* daemon. Every agent — whether it participates or not — gets a
|
|
15
|
+
* baseline record synthesized from what the daemon already sees
|
|
16
|
+
* (`synthesize_baseline_usage`), so the "every agent is measurable"
|
|
17
|
+
* property does not depend on agent-author cooperation.
|
|
18
|
+
*
|
|
19
|
+
* See `CONVENTIONS.md` in this folder for the per-agent-kind mapping
|
|
20
|
+
* of `unit_kind` / `units_in` / `units_out` and copy/paste snippets.
|
|
21
|
+
*/
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
/** Broad categorisation of an agent invocation. */
|
|
24
|
+
export declare const AGENT_KINDS: readonly ["llm", "connector", "shell", "gate", "builder", "custom"];
|
|
25
|
+
/** One of {@link AGENT_KINDS}. */
|
|
26
|
+
export type AgentKind = typeof AGENT_KINDS[number];
|
|
27
|
+
/**
|
|
28
|
+
* The unit of work an agent counts. Each `agent_kind` maps its
|
|
29
|
+
* native concept onto this shared enum so aggregation queries can
|
|
30
|
+
* `GROUP BY unit_kind` without adding tokens to bytes.
|
|
31
|
+
*
|
|
32
|
+
* llm → tokens
|
|
33
|
+
* connector → calls
|
|
34
|
+
* shell → bytes
|
|
35
|
+
* builder → files
|
|
36
|
+
* gate → records (criteria evaluated)
|
|
37
|
+
* custom → none (or agent's choice)
|
|
38
|
+
*/
|
|
39
|
+
export declare const UNIT_KINDS: readonly ["tokens", "calls", "bytes", "records", "files", "none"];
|
|
40
|
+
/** One of {@link UNIT_KINDS}. */
|
|
41
|
+
export type UnitKind = typeof UNIT_KINDS[number];
|
|
42
|
+
/** How an agent invocation ended. */
|
|
43
|
+
export declare const OUTCOMES: readonly ["success", "failure", "cancelled", "timeout"];
|
|
44
|
+
/** One of {@link OUTCOMES}. */
|
|
45
|
+
export type Outcome = typeof OUTCOMES[number];
|
|
46
|
+
/**
|
|
47
|
+
* Bump when adding required fields or changing semantics. Optional
|
|
48
|
+
* additions can go into the current version and be safely ignored
|
|
49
|
+
* by older daemons.
|
|
50
|
+
*/
|
|
51
|
+
export declare const USAGE_RECORD_VERSION: 1;
|
|
52
|
+
/**
|
|
53
|
+
* The full record. `report_usage` accepts a partial and fills the
|
|
54
|
+
* required fields from environment + timing where possible; the
|
|
55
|
+
* daemon then merges + validates the full record before stamping
|
|
56
|
+
* it on the agent.execute span.
|
|
57
|
+
*/
|
|
58
|
+
export declare const usage_record_schema: z.ZodObject<{
|
|
59
|
+
version: z.ZodLiteral<1>;
|
|
60
|
+
agent_name: z.ZodString;
|
|
61
|
+
agent_kind: z.ZodEnum<{
|
|
62
|
+
custom: "custom";
|
|
63
|
+
gate: "gate";
|
|
64
|
+
llm: "llm";
|
|
65
|
+
connector: "connector";
|
|
66
|
+
shell: "shell";
|
|
67
|
+
builder: "builder";
|
|
68
|
+
}>;
|
|
69
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
70
|
+
model: z.ZodOptional<z.ZodString>;
|
|
71
|
+
started_at_unix_ms: z.ZodNumber;
|
|
72
|
+
ended_at_unix_ms: z.ZodNumber;
|
|
73
|
+
duration_ms: z.ZodNumber;
|
|
74
|
+
outcome: z.ZodEnum<{
|
|
75
|
+
success: "success";
|
|
76
|
+
timeout: "timeout";
|
|
77
|
+
cancelled: "cancelled";
|
|
78
|
+
failure: "failure";
|
|
79
|
+
}>;
|
|
80
|
+
exit_code: z.ZodNullable<z.ZodNumber>;
|
|
81
|
+
error_class: z.ZodOptional<z.ZodString>;
|
|
82
|
+
unit_kind: z.ZodOptional<z.ZodEnum<{
|
|
83
|
+
files: "files";
|
|
84
|
+
tokens: "tokens";
|
|
85
|
+
calls: "calls";
|
|
86
|
+
bytes: "bytes";
|
|
87
|
+
records: "records";
|
|
88
|
+
none: "none";
|
|
89
|
+
}>>;
|
|
90
|
+
units_in: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
units_out: z.ZodOptional<z.ZodNumber>;
|
|
92
|
+
cost_usd: z.ZodOptional<z.ZodNumber>;
|
|
93
|
+
attempts: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
external_calls: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
extras: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
/** A complete usage record (the shape {@link usage_record_schema} validates). */
|
|
98
|
+
export type UsageRecord = z.infer<typeof usage_record_schema>;
|
|
99
|
+
/**
|
|
100
|
+
* Shape accepted from agents at `report_usage(...)` time. Every
|
|
101
|
+
* field except `agent_kind` + at least one of the volume fields is
|
|
102
|
+
* optional; the SDK / daemon fill the rest. `agent_kind` is
|
|
103
|
+
* required because it drives the unit-kind mapping and the rollup
|
|
104
|
+
* bucket, and only the agent knows what it is.
|
|
105
|
+
*/
|
|
106
|
+
export declare const usage_record_partial_schema: z.ZodObject<{
|
|
107
|
+
version: z.ZodOptional<z.ZodLiteral<1>>;
|
|
108
|
+
agent_name: z.ZodOptional<z.ZodString>;
|
|
109
|
+
provider: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
110
|
+
model: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
111
|
+
started_at_unix_ms: z.ZodOptional<z.ZodNumber>;
|
|
112
|
+
ended_at_unix_ms: z.ZodOptional<z.ZodNumber>;
|
|
113
|
+
duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
114
|
+
outcome: z.ZodOptional<z.ZodEnum<{
|
|
115
|
+
success: "success";
|
|
116
|
+
timeout: "timeout";
|
|
117
|
+
cancelled: "cancelled";
|
|
118
|
+
failure: "failure";
|
|
119
|
+
}>>;
|
|
120
|
+
exit_code: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
121
|
+
error_class: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
122
|
+
unit_kind: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
123
|
+
files: "files";
|
|
124
|
+
tokens: "tokens";
|
|
125
|
+
calls: "calls";
|
|
126
|
+
bytes: "bytes";
|
|
127
|
+
records: "records";
|
|
128
|
+
none: "none";
|
|
129
|
+
}>>>;
|
|
130
|
+
units_in: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
131
|
+
units_out: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
132
|
+
cost_usd: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
133
|
+
attempts: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
134
|
+
external_calls: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
135
|
+
extras: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>>;
|
|
136
|
+
agent_kind: z.ZodEnum<{
|
|
137
|
+
custom: "custom";
|
|
138
|
+
gate: "gate";
|
|
139
|
+
llm: "llm";
|
|
140
|
+
connector: "connector";
|
|
141
|
+
shell: "shell";
|
|
142
|
+
builder: "builder";
|
|
143
|
+
}>;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
/** What an agent passes to `report_usage` (see {@link usage_record_partial_schema}). */
|
|
146
|
+
export type UsageRecordPartial = z.infer<typeof usage_record_partial_schema>;
|
|
147
|
+
/**
|
|
148
|
+
* Aggregate totals across a set of records — used for the run.execute
|
|
149
|
+
* and phase.execute rollups. Numbers are sums (or counts, where the
|
|
150
|
+
* field name says so); `undefined` inputs contribute 0.
|
|
151
|
+
*/
|
|
152
|
+
export interface UsageRollupTotals {
|
|
153
|
+
duration_ms: number;
|
|
154
|
+
cost_usd: number;
|
|
155
|
+
attempts: number;
|
|
156
|
+
external_calls: number;
|
|
157
|
+
failures: number;
|
|
158
|
+
invocations: number;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Sub-total for one `unit_kind` bucket. Emitted so dashboards can
|
|
162
|
+
* show "3247 tokens in / 921 out for LLM agents" without adding
|
|
163
|
+
* bytes into the same number.
|
|
164
|
+
*/
|
|
165
|
+
export interface UsageRollupByUnit {
|
|
166
|
+
unit_kind: UnitKind;
|
|
167
|
+
units_in: number;
|
|
168
|
+
units_out: number;
|
|
169
|
+
invocations: number;
|
|
170
|
+
}
|
|
171
|
+
/** Usage rolled up over many records: overall totals, per unit kind and per agent kind. */
|
|
172
|
+
export interface UsageRollup {
|
|
173
|
+
totals: UsageRollupTotals;
|
|
174
|
+
by_unit: Partial<Record<UnitKind, UsageRollupByUnit>>;
|
|
175
|
+
by_kind: Partial<Record<AgentKind, UsageRollupTotals>>;
|
|
176
|
+
}
|
|
177
|
+
/** A value an OTEL span attribute (and a usage extra) can hold. */
|
|
178
|
+
type SpanAttrValue = string | number | boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Flatten a UsageRecord onto `usage.*` attribute keys ready to apply
|
|
181
|
+
* to an OTEL span via `span.setAttribute(key, value)`. Extras become
|
|
182
|
+
* `usage.extras.<key>`. Dashboard queries read these back from
|
|
183
|
+
* `run_spans.attributes`.
|
|
184
|
+
*/
|
|
185
|
+
export declare function usage_to_span_attrs(record: UsageRecord): Record<string, SpanAttrValue>;
|
|
186
|
+
/**
|
|
187
|
+
* Read a UsageRecord back from a span's flat `usage.*` attributes.
|
|
188
|
+
* Returns `null` if the span predates Phase 1 usage or the stored
|
|
189
|
+
* data doesn't validate (e.g. mid-migration schema drift).
|
|
190
|
+
*
|
|
191
|
+
* Numeric attributes may arrive as strings when read from JSONB via
|
|
192
|
+
* Postgres row_to_json — coerce those before validating.
|
|
193
|
+
*/
|
|
194
|
+
export declare function span_attrs_to_usage(attrs: Record<string, unknown>): UsageRecord | null;
|
|
195
|
+
/**
|
|
196
|
+
* Aggregate a set of agent records into totals, by-unit-kind, and
|
|
197
|
+
* by-agent-kind subtotals. Used by the run executor when closing a
|
|
198
|
+
* phase.execute span and the root run.execute span.
|
|
199
|
+
*/
|
|
200
|
+
export declare function roll_up_usage(records: readonly UsageRecord[]): UsageRollup;
|
|
201
|
+
/**
|
|
202
|
+
* Flatten a rollup onto dotted-key attributes ready to stamp on a
|
|
203
|
+
* parent span. `prefix` is typically `'run.usage'` or `'phase.usage'`.
|
|
204
|
+
* Keys look like:
|
|
205
|
+
* {prefix}.total_cost_usd
|
|
206
|
+
* {prefix}.total_duration_ms
|
|
207
|
+
* {prefix}.total_invocations
|
|
208
|
+
* {prefix}.total_failures
|
|
209
|
+
* {prefix}.total_attempts
|
|
210
|
+
* {prefix}.<unit_kind>.units_in
|
|
211
|
+
* {prefix}.<unit_kind>.units_out
|
|
212
|
+
* {prefix}.<agent_kind>.cost_usd
|
|
213
|
+
* {prefix}.<agent_kind>.duration_ms
|
|
214
|
+
* {prefix}.<agent_kind>.invocations
|
|
215
|
+
* {prefix}.<agent_kind>.failures
|
|
216
|
+
*/
|
|
217
|
+
export declare function rollup_to_span_attrs(rollup: UsageRollup, prefix: string): Record<string, number>;
|
|
218
|
+
/**
|
|
219
|
+
* Fields the daemon can auto-fill from what it already sees around
|
|
220
|
+
* every agent invocation — no cooperation required from the agent.
|
|
221
|
+
* The daemon calls `synthesize_baseline_usage(...)` in
|
|
222
|
+
* `run_executor.ts::spawn_and_invoke` at the finish() point.
|
|
223
|
+
*/
|
|
224
|
+
export interface BaselineInputs {
|
|
225
|
+
agent_name: string;
|
|
226
|
+
agent_kind: AgentKind;
|
|
227
|
+
spawn_at_unix_ms: number;
|
|
228
|
+
exit_at_unix_ms: number;
|
|
229
|
+
exit_code: number | null;
|
|
230
|
+
outcome: Outcome;
|
|
231
|
+
error_class?: string;
|
|
232
|
+
/** Bytes captured on the child's stdout (proxy for "work in"). */
|
|
233
|
+
stdin_bytes?: number;
|
|
234
|
+
stdout_bytes?: number;
|
|
235
|
+
stderr_bytes?: number;
|
|
236
|
+
attempts?: number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Produce a valid UsageRecord entirely from what the daemon
|
|
240
|
+
* observes. For shell/connector agents this is often the only
|
|
241
|
+
* record that will exist; LLM agents may `report_usage(...)` a
|
|
242
|
+
* richer record on top and the daemon calls `merge_usage`.
|
|
243
|
+
*/
|
|
244
|
+
export declare function synthesize_baseline_usage(input: BaselineInputs): UsageRecord;
|
|
245
|
+
/**
|
|
246
|
+
* Merge an agent-reported record on top of a daemon-baseline record.
|
|
247
|
+
*
|
|
248
|
+
* Daemon owns (never overridden by agent):
|
|
249
|
+
* agent_name, agent_kind, started_at_unix_ms, ended_at_unix_ms,
|
|
250
|
+
* duration_ms, exit_code, outcome
|
|
251
|
+
*
|
|
252
|
+
* Everything else takes the agent's value if provided.
|
|
253
|
+
*/
|
|
254
|
+
export declare function merge_usage(baseline: UsageRecord, agent_reported: UsageRecordPartial): UsageRecord;
|
|
255
|
+
/** Overrides for {@link report_usage}; each falls back to its env var. */
|
|
256
|
+
export interface ReportUsageOptions {
|
|
257
|
+
/** Defaults to `process.env.CLIQ_DAEMON_URL`. */
|
|
258
|
+
daemon_url?: string;
|
|
259
|
+
/** Defaults to `process.env.CLIQ_RUN_ID`. */
|
|
260
|
+
run_id?: string;
|
|
261
|
+
/** Defaults to `process.env.CLIQ_PHASE`. */
|
|
262
|
+
phase?: string;
|
|
263
|
+
/** Defaults to `process.env.CLIQ_AGENT` or `record.agent_name`. */
|
|
264
|
+
agent_name?: string;
|
|
265
|
+
/**
|
|
266
|
+
* Injected `fetch` for tests. Defaults to the global `fetch`.
|
|
267
|
+
* Return value is ignored — the poster is fire-and-forget.
|
|
268
|
+
*/
|
|
269
|
+
fetch_impl?: typeof fetch;
|
|
270
|
+
}
|
|
271
|
+
/** A usage record failed schema validation; `issues` holds the Zod issues. */
|
|
272
|
+
export declare class UsageValidationError extends Error {
|
|
273
|
+
readonly issues: unknown;
|
|
274
|
+
constructor(message: string, issues: unknown);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Report a usage record to the daemon. The daemon merges it onto
|
|
278
|
+
* the auto-baseline and stamps the final record on the agent.execute
|
|
279
|
+
* span attributes as `usage.*`.
|
|
280
|
+
*
|
|
281
|
+
* Fire-and-forget: the returned promise resolves on POST send (or
|
|
282
|
+
* catches the network error silently), so callers do not need to
|
|
283
|
+
* await it. Validation failures throw synchronously so agent-author
|
|
284
|
+
* tests catch them.
|
|
285
|
+
*/
|
|
286
|
+
export declare function report_usage(partial: UsageRecordPartial, options?: ReportUsageOptions): Promise<void>;
|
|
287
|
+
export {};
|
|
288
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/telemetry/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,mDAAmD;AACnD,eAAO,MAAM,WAAW,qEAOd,CAAC;AACX,kCAAkC;AAClC,MAAM,MAAM,SAAS,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,mEAOb,CAAC;AACX,iCAAiC;AACjC,MAAM,MAAM,QAAQ,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAEjD,qCAAqC;AACrC,eAAO,MAAM,QAAQ,yDAA0D,CAAC;AAChF,+BAA+B;AAC/B,MAAM,MAAM,OAAO,GAAG,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAK9C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAG,CAAU,CAAC;AAQ/C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiC9B,CAAC;AACH,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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