@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,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the cliq daemon (the CLI's view of its API).
|
|
3
|
+
*
|
|
4
|
+
* `call(route, input)` POSTs the route's plain input and resolves with the
|
|
5
|
+
* reply's `data` (`daemon_wire.ts`). It throws:
|
|
6
|
+
*
|
|
7
|
+
* - `DaemonError` when cliqd answered with a failure (`{ ok: false,
|
|
8
|
+
* error: { code, message, details } }`, any non-2xx, or a body that is
|
|
9
|
+
* not a cliqd reply) — `status`, `code`, `details`, `request_id`;
|
|
10
|
+
* - `DaemonUnreachableError` when it did not answer (connection refused,
|
|
11
|
+
* DNS failure, timeout), with the original error on `cause`.
|
|
12
|
+
*
|
|
13
|
+
* The target is a route name (`team_list` → `/v1/teams/get`, see
|
|
14
|
+
* {@link DAEMON_ROUTES}) or a route path (`/v1/runs/logs`).
|
|
15
|
+
*
|
|
16
|
+
* Auth: when a token is supplied it rides in the `Authorization`
|
|
17
|
+
* header as `Bearer <token>` — never in the payload. An UNAUTHORIZED
|
|
18
|
+
* reply triggers one token refresh and retry.
|
|
19
|
+
*/
|
|
20
|
+
import { randomUUID } from 'node:crypto';
|
|
21
|
+
import { DaemonError, read_daemon_reply } from './daemon_wire.js';
|
|
22
|
+
/** Route names → daemon route paths. */
|
|
23
|
+
export const DAEMON_ROUTES = {
|
|
24
|
+
init: '/v1/workspaces/init',
|
|
25
|
+
assemble_team: '/v1/workspaces/assemble_team',
|
|
26
|
+
workspace_remove_team: '/v1/workspaces/remove_team',
|
|
27
|
+
run: '/v1/workspaces/run',
|
|
28
|
+
status: '/v1/workspaces/status',
|
|
29
|
+
workspace_list: '/v1/workspaces/get',
|
|
30
|
+
clean: '/v1/workspaces/clean',
|
|
31
|
+
remove: '/v1/workspaces/remove',
|
|
32
|
+
doctor: '/v1/workspaces/doctor',
|
|
33
|
+
settings_get: '/v1/settings/get_by_key',
|
|
34
|
+
settings_set: '/v1/settings/set',
|
|
35
|
+
settings_list: '/v1/settings/get',
|
|
36
|
+
team_install: '/v1/teams/install',
|
|
37
|
+
team_uninstall: '/v1/teams/uninstall',
|
|
38
|
+
team_list: '/v1/teams/get',
|
|
39
|
+
team_search: '/v1/teams/search',
|
|
40
|
+
team_info: '/v1/teams/get_by_name',
|
|
41
|
+
team_update: '/v1/teams/update',
|
|
42
|
+
team_publish: '/v1/teams/publish',
|
|
43
|
+
team_validate: '/v1/teams/validate',
|
|
44
|
+
team_hub_install: '/v1/teams/hub_install',
|
|
45
|
+
agent_list: '/v1/agents/get',
|
|
46
|
+
agent_get_by_id: '/v1/agents/get_by_id',
|
|
47
|
+
agent_register: '/v1/agents/register',
|
|
48
|
+
agent_unregister: '/v1/agents/unregister',
|
|
49
|
+
instance_list: '/v1/instances/get',
|
|
50
|
+
instance_info: '/v1/instances/get_by_id',
|
|
51
|
+
instance_kill: '/v1/instances/stop',
|
|
52
|
+
daemon_status: '/v1/daemon/status',
|
|
53
|
+
hub_login: '/v1/login',
|
|
54
|
+
hub_logout: '/v1/logout',
|
|
55
|
+
hub_token: '/v1/auth/token',
|
|
56
|
+
hub_rotate_dispatch: '/v1/auth/rotate_dispatch',
|
|
57
|
+
token_create: '/v1/tokens/create',
|
|
58
|
+
token_list: '/v1/tokens/get',
|
|
59
|
+
token_revoke: '/v1/tokens/revoke',
|
|
60
|
+
resume_run: '/v1/runs/resume',
|
|
61
|
+
run_list: '/v1/runs/get',
|
|
62
|
+
runs_tree: '/v1/runs/tree',
|
|
63
|
+
hugs_next: '/v1/hugs/next',
|
|
64
|
+
hugs_respond: '/v1/hugs/respond',
|
|
65
|
+
hugs_dev: '/v1/hugs/dev',
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Raised when the daemon could not be reached at all (connection
|
|
69
|
+
* refused, DNS failure, or timeout) — distinct from an `error`
|
|
70
|
+
* envelope, which means the daemon answered. The original error is
|
|
71
|
+
* preserved on `cause` so callers can branch on `ECONNREFUSED`.
|
|
72
|
+
*/
|
|
73
|
+
export class DaemonUnreachableError extends Error {
|
|
74
|
+
url;
|
|
75
|
+
request_id;
|
|
76
|
+
constructor(url, cause, request_id = null) {
|
|
77
|
+
const suffix = request_id ? ` (request_id=${request_id})` : '';
|
|
78
|
+
super(`cliq daemon is not reachable at ${url}${suffix}`);
|
|
79
|
+
this.name = 'DaemonUnreachableError';
|
|
80
|
+
this.url = url;
|
|
81
|
+
this.request_id = request_id;
|
|
82
|
+
this.cause = cause;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Client for the local cliqd HTTP API (`http://<host>:<port>`). Every call is a
|
|
87
|
+
* POST of a plain input that resolves with the reply's `data`; one retry after
|
|
88
|
+
* an UNAUTHORIZED reply when a `token_provider` can mint a fresh token.
|
|
89
|
+
*/
|
|
90
|
+
export class HttpDaemonClient {
|
|
91
|
+
base_url;
|
|
92
|
+
timeout_ms;
|
|
93
|
+
token;
|
|
94
|
+
token_provider;
|
|
95
|
+
_last_request_id = null;
|
|
96
|
+
constructor(options = {}) {
|
|
97
|
+
const host = options.host ?? '127.0.0.1';
|
|
98
|
+
const port = options.port ?? 4900;
|
|
99
|
+
this.base_url = `http://${host}:${port}`;
|
|
100
|
+
this.timeout_ms = options.timeout_ms ?? 30_000;
|
|
101
|
+
this.token = options.token ?? null;
|
|
102
|
+
this.token_provider = options.token_provider ?? null;
|
|
103
|
+
}
|
|
104
|
+
/** Most recent outbound `x-request-id` (for correlating with daemon logs). */
|
|
105
|
+
get last_request_id() {
|
|
106
|
+
return this._last_request_id;
|
|
107
|
+
}
|
|
108
|
+
/** Factory mirror of the constructor for call-site symmetry. */
|
|
109
|
+
static create(options = {}) {
|
|
110
|
+
return new HttpDaemonClient(options);
|
|
111
|
+
}
|
|
112
|
+
/** The daemon route path of a route name. */
|
|
113
|
+
static route_for(name) {
|
|
114
|
+
const route = DAEMON_ROUTES[name];
|
|
115
|
+
if (!route)
|
|
116
|
+
throw new Error(`No daemon route named "${name}"`);
|
|
117
|
+
return route;
|
|
118
|
+
}
|
|
119
|
+
/** The route path for a call target (a path is returned as-is). */
|
|
120
|
+
static path_for(target) {
|
|
121
|
+
return target.startsWith('/') ? target : HttpDaemonClient.route_for(target);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* POST `input` to the target's route and resolve with the reply's `data`.
|
|
125
|
+
*
|
|
126
|
+
* @param target - Route name (`team_list`) or route path (`/v1/runs/logs`).
|
|
127
|
+
* @param input - The route's plain input object (default `{}`).
|
|
128
|
+
* @param options - Per-call timeout.
|
|
129
|
+
* @throws DaemonError when cliqd answered with a failure; DaemonUnreachableError when it did not answer.
|
|
130
|
+
*/
|
|
131
|
+
async call(target, input = {}, options = {}) {
|
|
132
|
+
await this._ensure_token();
|
|
133
|
+
try {
|
|
134
|
+
return await this._call_once(target, input, options);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (!(err instanceof DaemonError) || err.code !== 'UNAUTHORIZED' || !this.token_provider)
|
|
138
|
+
throw err;
|
|
139
|
+
this.token = await this.token_provider();
|
|
140
|
+
if (!this.token)
|
|
141
|
+
throw err;
|
|
142
|
+
return this._call_once(target, input, options);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** One POST of the plain input (see {@link call}). */
|
|
146
|
+
async _call_once(target, input, options) {
|
|
147
|
+
const url = `${this.base_url}${HttpDaemonClient.path_for(target)}`;
|
|
148
|
+
const request_id = randomUUID();
|
|
149
|
+
this._last_request_id = request_id;
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
const timer = setTimeout(() => controller.abort(), options.timeout_ms ?? this.timeout_ms);
|
|
152
|
+
let response;
|
|
153
|
+
let text;
|
|
154
|
+
try {
|
|
155
|
+
response = await fetch(url, {
|
|
156
|
+
method: 'POST',
|
|
157
|
+
headers: this._headers(request_id),
|
|
158
|
+
body: JSON.stringify(input ?? {}),
|
|
159
|
+
signal: controller.signal,
|
|
160
|
+
});
|
|
161
|
+
text = await response.text();
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
throw new DaemonUnreachableError(url, err, request_id);
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
clearTimeout(timer);
|
|
168
|
+
}
|
|
169
|
+
const echoed = response.headers?.get?.('x-request-id');
|
|
170
|
+
if (echoed?.trim())
|
|
171
|
+
this._last_request_id = echoed.trim();
|
|
172
|
+
return read_daemon_reply(response.status, text, this._last_request_id);
|
|
173
|
+
}
|
|
174
|
+
async _ensure_token() {
|
|
175
|
+
if (this.token)
|
|
176
|
+
return;
|
|
177
|
+
if (!this.token_provider)
|
|
178
|
+
return;
|
|
179
|
+
this.token = await this.token_provider();
|
|
180
|
+
}
|
|
181
|
+
/** Build request headers, adding the bearer token when present. */
|
|
182
|
+
_headers(request_id) {
|
|
183
|
+
const headers = {
|
|
184
|
+
'content-type': 'application/json',
|
|
185
|
+
'x-request-id': request_id,
|
|
186
|
+
};
|
|
187
|
+
if (this.token)
|
|
188
|
+
headers['authorization'] = `Bearer ${this.token}`;
|
|
189
|
+
return headers;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=http_daemon_client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http_daemon_client.js","sourceRoot":"","sources":["../src/http_daemon_client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAElE,wCAAwC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,IAAI,EAAmB,qBAAqB;IAC5C,aAAa,EAAU,8BAA8B;IACrD,qBAAqB,EAAE,4BAA4B;IACnD,GAAG,EAAoB,oBAAoB;IAC3C,MAAM,EAAiB,uBAAuB;IAC9C,cAAc,EAAS,oBAAoB;IAC3C,KAAK,EAAkB,sBAAsB;IAC7C,MAAM,EAAiB,uBAAuB;IAC9C,MAAM,EAAiB,uBAAuB;IAE9C,YAAY,EAAW,yBAAyB;IAChD,YAAY,EAAW,kBAAkB;IACzC,aAAa,EAAU,kBAAkB;IAEzC,YAAY,EAAW,mBAAmB;IAC1C,cAAc,EAAS,qBAAqB;IAC5C,SAAS,EAAc,eAAe;IACtC,WAAW,EAAY,kBAAkB;IACzC,SAAS,EAAc,uBAAuB;IAC9C,WAAW,EAAY,kBAAkB;IACzC,YAAY,EAAW,mBAAmB;IAC1C,aAAa,EAAU,oBAAoB;IAC3C,gBAAgB,EAAO,uBAAuB;IAE9C,UAAU,EAAa,gBAAgB;IACvC,eAAe,EAAQ,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,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,IAAI,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;gBAAS,CAAC;YACP,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC;QACvD,IAAI,MAAM,EAAE,IAAI,EAAE;YAAE,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC1D,OAAO,iBAAiB,CAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9E,CAAC;IAEO,KAAK,CAAC,aAAa;QACvB,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QACvB,IAAI,CAAC,IAAI,CAAC,cAAc;YAAE,OAAO;QACjC,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IAC7C,CAAC;IAED,mEAAmE;IAC3D,QAAQ,CAAC,UAAkB;QAC/B,MAAM,OAAO,GAA2B;YACpC,cAAc,EAAE,kBAAkB;YAClC,cAAc,EAAE,UAAU;SAC7B,CAAC;QACF,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,IAAI,CAAC,KAAK,EAAE,CAAC;QAClE,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ctx.hug` and `ctx.ask()` (PLAN-hug-requests §10.1, §10.3, §10.4; PLAN-hug-widgets §9.1) — the agent's way to ask
|
|
3
|
+
* people. `ctx.ask(hug, …)` opens a Hug with a hug (its imported definition, or its name), runs the requester's policy
|
|
4
|
+
* on each event, and returns once the policy is done (or throws when it fails); with `wait: 'yield'` the agent process
|
|
5
|
+
* ends while people answer, and cliqd re-invokes the phase when they do.
|
|
6
|
+
*
|
|
7
|
+
* **Checking (F3):** the params are checked against the hug's definition before anything is sent, and every response
|
|
8
|
+
* is checked against its `values(params)` before the policy sees it. A response that fails is never treated as valid:
|
|
9
|
+
* with `on_invalid: 'ignore'` (the only mode for now) it isn't counted, the problems are logged, and a progress line
|
|
10
|
+
* says an answer couldn't be used; the person may answer again while the Hug is open.
|
|
11
|
+
*
|
|
12
|
+
* Each `ctx.ask` call gets a stable request id (`<phase>#<iteration>#ask<n>`): when the agent's code runs again (a
|
|
13
|
+
* restart, or a resume whose policy has functions), the same call finds the same Hug (cliqd dedups `open` on it) and
|
|
14
|
+
* its events, instead of asking again. A Hug the requester already settled comes back in `resume.hugs` with its result
|
|
15
|
+
* saved, so a replayed call returns (or throws) that result at once.
|
|
16
|
+
*/
|
|
17
|
+
import { HugClient, type HugDefaults, type HugTransport } from './client.js';
|
|
18
|
+
import type { HugDefinition } from './define.js';
|
|
19
|
+
import { HugError } from './errors.js';
|
|
20
|
+
import { HugDefinitions } from './hug_definitions.js';
|
|
21
|
+
import { type Policy, type PolicyResult } from './policies.js';
|
|
22
|
+
import { HugSession } from './session.js';
|
|
23
|
+
import { type Attachment, type HugEvent, type HugReminders, type HugResponse, type HugResumeEntry, type HugSpec } from './types.js';
|
|
24
|
+
/** What to do with a response that fails the definition's check. */
|
|
25
|
+
export type OnInvalid = 'ignore';
|
|
26
|
+
/** What `ctx.ask` takes besides the hug: the Hug's envelope, and how to wait and when it's done. */
|
|
27
|
+
export interface AskOptions<P = Record<string, unknown>, T = Readonly<Record<string, unknown>>> {
|
|
28
|
+
/** Shown in the Hub's chrome, notifications, reminders and the inbox. */
|
|
29
|
+
readonly title: string;
|
|
30
|
+
/** The hug's input, checked against its definition before the Hug opens. */
|
|
31
|
+
readonly params?: P;
|
|
32
|
+
/** Plain text for where the frontend can't be (notifications, the inbox). */
|
|
33
|
+
readonly summary?: string;
|
|
34
|
+
/** Run files the frontend may read (`ctx.attach`). */
|
|
35
|
+
readonly attachments?: readonly Attachment[];
|
|
36
|
+
readonly channels?: readonly string[];
|
|
37
|
+
readonly expires_in_min?: number;
|
|
38
|
+
readonly reminders?: HugReminders;
|
|
39
|
+
/** Default `any()`: the first valid response. */
|
|
40
|
+
readonly policy?: Policy<T>;
|
|
41
|
+
/** `block` (default) keeps the process waiting; `yield` ends it while people answer. */
|
|
42
|
+
readonly wait?: 'block' | 'yield';
|
|
43
|
+
/** A response that fails the check: `ignore` (default) — not counted; the person may answer again. */
|
|
44
|
+
readonly on_invalid?: OnInvalid;
|
|
45
|
+
}
|
|
46
|
+
/** @deprecated The name of {@link AskOptions} before hugs. */
|
|
47
|
+
export type AskSpec<T = Readonly<Record<string, unknown>>> = AskOptions<Record<string, unknown>, T>;
|
|
48
|
+
/** What a finished `ctx.ask` returns. */
|
|
49
|
+
export interface AskResult<T> {
|
|
50
|
+
/** The policy's value (`any()`: the one valid response's checked values). */
|
|
51
|
+
readonly value: T;
|
|
52
|
+
/** Same as `value` (the name before hugs). */
|
|
53
|
+
readonly values: T;
|
|
54
|
+
/** Every valid response received (latest per responder), with checked values. */
|
|
55
|
+
readonly responses: readonly HugResponse[];
|
|
56
|
+
/** The close text. */
|
|
57
|
+
readonly outcome: string;
|
|
58
|
+
readonly hug_id: string;
|
|
59
|
+
}
|
|
60
|
+
/** How a resumed Hug ended up after its stored policy re-ran (§10.4). */
|
|
61
|
+
export interface ResumedOutcome {
|
|
62
|
+
readonly session: HugSession;
|
|
63
|
+
/** The policy's result; null when the policy has functions (the agent's `ctx.ask` re-runs it). */
|
|
64
|
+
readonly result: PolicyResult<unknown> | null;
|
|
65
|
+
/**
|
|
66
|
+
* The Hug's valid responses, each checked against the hug's definition (latest per responder) — what an agent may
|
|
67
|
+
* act on. Responses the definition refused are never here. Empty when the policy has functions.
|
|
68
|
+
*/
|
|
69
|
+
readonly responses: readonly HugResponse[];
|
|
70
|
+
}
|
|
71
|
+
/** The low-level interface on `ctx.hug`. */
|
|
72
|
+
export interface HugApi {
|
|
73
|
+
/** Open a Hug (phase defaults filled in) and return its session. The spec is sent as given (no definition check). */
|
|
74
|
+
open(spec: HugSpec, opts?: {
|
|
75
|
+
state?: unknown;
|
|
76
|
+
}): Promise<HugSession>;
|
|
77
|
+
/** Sessions restored on resume (one per entry in `invoke.resume.hugs`). */
|
|
78
|
+
resumed(): HugSession[];
|
|
79
|
+
}
|
|
80
|
+
/** `ctx.ask`: with a hug's definition (typed), its name, or neither (the phase's hug, else `form`). */
|
|
81
|
+
export interface Ask {
|
|
82
|
+
<P, V, T = V>(hug: HugDefinition<P, V>, opts: AskOptions<P, T>): Promise<AskResult<T>>;
|
|
83
|
+
<T = Readonly<Record<string, unknown>>>(hug: string, opts: AskOptions<Record<string, unknown>, T>): Promise<AskResult<T>>;
|
|
84
|
+
<T = Readonly<Record<string, unknown>>>(opts: AskOptions<Record<string, unknown>, T>): Promise<AskResult<T>>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Thrown by `ctx.ask(… wait: 'yield')` after the phase has yielded: the agent's code stops here and
|
|
88
|
+
* the process ends. `BaseAgent` swallows it; don't catch it.
|
|
89
|
+
*/
|
|
90
|
+
export declare class HugYield extends Error {
|
|
91
|
+
constructor();
|
|
92
|
+
}
|
|
93
|
+
/** What the asker needs from the agent context. */
|
|
94
|
+
export interface AskerDeps {
|
|
95
|
+
readonly transport: HugTransport;
|
|
96
|
+
readonly defaults: HugDefaults;
|
|
97
|
+
/** Posts the `phase.waiting` terminator (ctx.wait). */
|
|
98
|
+
readonly wait: (opts: {
|
|
99
|
+
sessions: HugSession[];
|
|
100
|
+
state?: unknown;
|
|
101
|
+
}) => Promise<void>;
|
|
102
|
+
/** Posts a progress line (the policy's status while it waits). */
|
|
103
|
+
readonly progress: (message: string) => void;
|
|
104
|
+
/** Writes to the run's log (a response that couldn't be used, and why). Default: stderr. */
|
|
105
|
+
readonly log?: (message: string) => void;
|
|
106
|
+
/** `invoke.resume.hugs`, when this invoke is a resume. */
|
|
107
|
+
readonly resume?: readonly HugResumeEntry[];
|
|
108
|
+
/** Definitions by name (default: from `CLIQ_HUGS` and the built-ins). */
|
|
109
|
+
readonly definitions?: HugDefinitions;
|
|
110
|
+
/** The phase's hug, for a `ctx.ask` that names none (default: `CLIQ_HUG_NAME`, else `form`). */
|
|
111
|
+
readonly phase_hug?: string;
|
|
112
|
+
}
|
|
113
|
+
/** One phase iteration's Hug machinery: `ctx.hug`, `ctx.ask` and the resume step. */
|
|
114
|
+
export declare class Asker {
|
|
115
|
+
private readonly _deps;
|
|
116
|
+
readonly client: HugClient;
|
|
117
|
+
private readonly _resumed;
|
|
118
|
+
/** Results the resume step already reached, by request id. */
|
|
119
|
+
private readonly _settled;
|
|
120
|
+
private readonly _definitions;
|
|
121
|
+
/** Responses already found invalid, by `response_id`, so each is logged once. */
|
|
122
|
+
private readonly _invalid;
|
|
123
|
+
private _asks;
|
|
124
|
+
constructor(_deps: AskerDeps);
|
|
125
|
+
/** `ctx.hug`. */
|
|
126
|
+
api(): HugApi;
|
|
127
|
+
/** `ctx.ask()`, as the agent context exposes it. */
|
|
128
|
+
readonly ask: Ask;
|
|
129
|
+
private _ask;
|
|
130
|
+
private _phase_hug;
|
|
131
|
+
/** Run the policy on the session's valid responses until it is done (or fails); a yield parks the phase. */
|
|
132
|
+
private _settle;
|
|
133
|
+
/** The policy on one event, with only valid responses; an invalid response is logged and waits. */
|
|
134
|
+
private _evaluate;
|
|
135
|
+
/** Log why a response couldn't be used (once per response), and say on the Hug page how many couldn't. */
|
|
136
|
+
private _report_invalid;
|
|
137
|
+
/** A status line: the phase's progress, and the Hug's own line for the people answering it (§6.1). */
|
|
138
|
+
private _say;
|
|
139
|
+
/**
|
|
140
|
+
* For an agent that doesn't replay its earlier asks (the LLM and CLI agents): number the next ask after every Hug
|
|
141
|
+
* this phase iteration already opened, so it opens a new Hug instead of finding a settled one by position.
|
|
142
|
+
*/
|
|
143
|
+
continue_after_resumed(): void;
|
|
144
|
+
/**
|
|
145
|
+
* The resume step (§10.4), before the agent's code runs: re-run each resumed Hug's stored
|
|
146
|
+
* policy (one without code) on its new events. Returns null when every resumed Hug has one and
|
|
147
|
+
* is still waiting — the phase has yielded again and the agent's code must not run. Otherwise
|
|
148
|
+
* what happened; a Hug whose policy has functions comes back with `result: null`, and the
|
|
149
|
+
* agent's `ctx.ask` re-runs that policy.
|
|
150
|
+
*/
|
|
151
|
+
resume(): Promise<ResumedOutcome[] | null>;
|
|
152
|
+
private _rerun;
|
|
153
|
+
private _open;
|
|
154
|
+
private _yield;
|
|
155
|
+
}
|
|
156
|
+
/** The error a failed policy raises: expired / cancelled, a rejection (with its response), or the policy's own reason. */
|
|
157
|
+
export declare function error_for(hug_id: string, reason: string, response?: HugResponse): HugError;
|
|
158
|
+
/** Re-exported for agents that read events themselves. */
|
|
159
|
+
export type { HugEvent };
|
|
160
|
+
//# sourceMappingURL=ask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/hug/ask.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAqB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAqB,QAAQ,EAAsD,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAE,cAAc,EAAkB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAoB,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,UAAU,EAA4D,MAAM,cAAc,CAAC;AACpG,OAAO,EACY,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO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