@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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `form` — the built-in hug that asks for some answers (PLAN-hug-widgets §10.1). Its params list the fields
|
|
3
|
+
* (`inputs`), so its answer schema, upload slots and summary are built from them.
|
|
4
|
+
*
|
|
5
|
+
* Answer: one key per input (required ones enforced) and an optional `comment`; or, when the person can't answer,
|
|
6
|
+
* `{ declined: "<reason>" }` and nothing else. The same rules as today's `form_v1` (the parity is tested).
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/** The answer keys `form` adds itself; inputs can't use them. */
|
|
10
|
+
export declare const FORM_OWN_KEYS: readonly ["comment", "declined"];
|
|
11
|
+
/** `form`'s params. */
|
|
12
|
+
export declare const FormParams: z.ZodObject<{
|
|
13
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
14
|
+
context: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
+
type: z.ZodLiteral<"markdown">;
|
|
16
|
+
text: z.ZodString;
|
|
17
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
18
|
+
type: z.ZodLiteral<"artifact">;
|
|
19
|
+
artifact_id: z.ZodString;
|
|
20
|
+
label: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"checks">;
|
|
23
|
+
results: z.ZodArray<z.ZodObject<{
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
ok: z.ZodBoolean;
|
|
26
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strict>>;
|
|
28
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
29
|
+
type: z.ZodLiteral<"transcript">;
|
|
30
|
+
turns: z.ZodArray<z.ZodObject<{
|
|
31
|
+
role: z.ZodString;
|
|
32
|
+
content: z.ZodString;
|
|
33
|
+
}, z.core.$strict>>;
|
|
34
|
+
}, z.core.$strict>], "type">>>;
|
|
35
|
+
inputs: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
36
|
+
type: z.ZodLiteral<"text">;
|
|
37
|
+
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
min_length: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
max_length: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
label: z.ZodOptional<z.ZodString>;
|
|
42
|
+
help: z.ZodOptional<z.ZodString>;
|
|
43
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
45
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
46
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
47
|
+
type: z.ZodLiteral<"number">;
|
|
48
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
integer: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
name: z.ZodString;
|
|
52
|
+
label: z.ZodOptional<z.ZodString>;
|
|
53
|
+
help: z.ZodOptional<z.ZodString>;
|
|
54
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
56
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
57
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
58
|
+
type: z.ZodLiteral<"boolean">;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
label: z.ZodOptional<z.ZodString>;
|
|
61
|
+
help: z.ZodOptional<z.ZodString>;
|
|
62
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
63
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
64
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
65
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
66
|
+
type: z.ZodLiteral<"enum">;
|
|
67
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
68
|
+
value: z.ZodString;
|
|
69
|
+
label: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strict>>;
|
|
71
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
name: z.ZodString;
|
|
73
|
+
label: z.ZodOptional<z.ZodString>;
|
|
74
|
+
help: z.ZodOptional<z.ZodString>;
|
|
75
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
76
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
77
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
78
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
79
|
+
type: z.ZodLiteral<"file">;
|
|
80
|
+
accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
81
|
+
max_bytes: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
83
|
+
name: z.ZodString;
|
|
84
|
+
label: z.ZodOptional<z.ZodString>;
|
|
85
|
+
help: z.ZodOptional<z.ZodString>;
|
|
86
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
87
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
88
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
89
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
90
|
+
type: z.ZodLiteral<"channel">;
|
|
91
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
name: z.ZodString;
|
|
93
|
+
label: z.ZodOptional<z.ZodString>;
|
|
94
|
+
help: z.ZodOptional<z.ZodString>;
|
|
95
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
96
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
97
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
}, z.core.$strict>], "type">>>;
|
|
99
|
+
}, z.core.$strict>;
|
|
100
|
+
/** `form`'s params. */
|
|
101
|
+
export type FormParams = z.infer<typeof FormParams>;
|
|
102
|
+
/** A `form` answer: the inputs and a comment, or `declined`. */
|
|
103
|
+
export type FormValues = {
|
|
104
|
+
declined: string;
|
|
105
|
+
} | ({
|
|
106
|
+
comment?: string | null;
|
|
107
|
+
} & Record<string, unknown>);
|
|
108
|
+
/** The built-in `form` hug. */
|
|
109
|
+
export declare const form: import("../define.js").HugDefinition<{
|
|
110
|
+
inputs: ({
|
|
111
|
+
type: "text";
|
|
112
|
+
name: string;
|
|
113
|
+
multiline?: boolean | undefined;
|
|
114
|
+
min_length?: number | undefined;
|
|
115
|
+
max_length?: number | undefined;
|
|
116
|
+
label?: string | undefined;
|
|
117
|
+
help?: string | undefined;
|
|
118
|
+
required?: boolean | undefined;
|
|
119
|
+
default?: unknown;
|
|
120
|
+
ui?: Record<string, unknown> | undefined;
|
|
121
|
+
} | {
|
|
122
|
+
type: "number";
|
|
123
|
+
name: string;
|
|
124
|
+
min?: number | undefined;
|
|
125
|
+
max?: number | undefined;
|
|
126
|
+
integer?: boolean | undefined;
|
|
127
|
+
label?: string | undefined;
|
|
128
|
+
help?: string | undefined;
|
|
129
|
+
required?: boolean | undefined;
|
|
130
|
+
default?: unknown;
|
|
131
|
+
ui?: Record<string, unknown> | undefined;
|
|
132
|
+
} | {
|
|
133
|
+
type: "boolean";
|
|
134
|
+
name: string;
|
|
135
|
+
label?: string | undefined;
|
|
136
|
+
help?: string | undefined;
|
|
137
|
+
required?: boolean | undefined;
|
|
138
|
+
default?: unknown;
|
|
139
|
+
ui?: Record<string, unknown> | undefined;
|
|
140
|
+
} | {
|
|
141
|
+
type: "enum";
|
|
142
|
+
choices: {
|
|
143
|
+
value: string;
|
|
144
|
+
label?: string | undefined;
|
|
145
|
+
}[];
|
|
146
|
+
name: string;
|
|
147
|
+
multiple?: boolean | undefined;
|
|
148
|
+
label?: string | undefined;
|
|
149
|
+
help?: string | undefined;
|
|
150
|
+
required?: boolean | undefined;
|
|
151
|
+
default?: unknown;
|
|
152
|
+
ui?: Record<string, unknown> | undefined;
|
|
153
|
+
} | {
|
|
154
|
+
type: "file";
|
|
155
|
+
name: string;
|
|
156
|
+
accept?: string[] | undefined;
|
|
157
|
+
max_bytes?: number | undefined;
|
|
158
|
+
multiple?: boolean | undefined;
|
|
159
|
+
label?: string | undefined;
|
|
160
|
+
help?: string | undefined;
|
|
161
|
+
required?: boolean | undefined;
|
|
162
|
+
default?: unknown;
|
|
163
|
+
ui?: Record<string, unknown> | undefined;
|
|
164
|
+
} | {
|
|
165
|
+
type: "channel";
|
|
166
|
+
name: string;
|
|
167
|
+
multiple?: boolean | undefined;
|
|
168
|
+
label?: string | undefined;
|
|
169
|
+
help?: string | undefined;
|
|
170
|
+
required?: boolean | undefined;
|
|
171
|
+
default?: unknown;
|
|
172
|
+
ui?: Record<string, unknown> | undefined;
|
|
173
|
+
})[];
|
|
174
|
+
prompt?: string | undefined;
|
|
175
|
+
context?: ({
|
|
176
|
+
type: "markdown";
|
|
177
|
+
text: string;
|
|
178
|
+
} | {
|
|
179
|
+
type: "artifact";
|
|
180
|
+
artifact_id: string;
|
|
181
|
+
label?: string | undefined;
|
|
182
|
+
} | {
|
|
183
|
+
type: "checks";
|
|
184
|
+
results: {
|
|
185
|
+
name: string;
|
|
186
|
+
ok: boolean;
|
|
187
|
+
summary?: string | undefined;
|
|
188
|
+
}[];
|
|
189
|
+
} | {
|
|
190
|
+
type: "transcript";
|
|
191
|
+
turns: {
|
|
192
|
+
role: string;
|
|
193
|
+
content: string;
|
|
194
|
+
}[];
|
|
195
|
+
})[] | undefined;
|
|
196
|
+
}, FormValues>;
|
|
197
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/hug/definitions/form.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,iEAAiE;AACjE,eAAO,MAAM,aAAa,kCAAmC,CAAC;AAE9D,uBAAuB;AACvB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAsE,CAAC;AAC9F,uBAAuB;AACvB,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAExG,+BAA+B;AAC/B,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAWf,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `form` — the built-in hug that asks for some answers (PLAN-hug-widgets §10.1). Its params list the fields
|
|
3
|
+
* (`inputs`), so its answer schema, upload slots and summary are built from them.
|
|
4
|
+
*
|
|
5
|
+
* Answer: one key per input (required ones enforced) and an optional `comment`; or, when the person can't answer,
|
|
6
|
+
* `{ declined: "<reason>" }` and nothing else. The same rules as today's `form_v1` (the parity is tested).
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { define_hug } from '../define.js';
|
|
10
|
+
import { schema_for_inputs } from '../schema_for_inputs.js';
|
|
11
|
+
import { base_params, file_inputs, first_answer, no_own_keys, note } from './common.js';
|
|
12
|
+
/** The answer keys `form` adds itself; inputs can't use them. */
|
|
13
|
+
export const FORM_OWN_KEYS = ['comment', 'declined'];
|
|
14
|
+
/** `form`'s params. */
|
|
15
|
+
export const FormParams = z.strictObject(base_params).superRefine(no_own_keys(FORM_OWN_KEYS));
|
|
16
|
+
/** The built-in `form` hug. */
|
|
17
|
+
export const form = define_hug({
|
|
18
|
+
name: 'form',
|
|
19
|
+
title: 'Form',
|
|
20
|
+
description: 'Asks people for a few values (text, numbers, yes/no, choices, files) and an optional comment; they may say they can\'t answer.',
|
|
21
|
+
params: FormParams,
|
|
22
|
+
values: (p) => z.union([
|
|
23
|
+
z.strictObject({ declined: note(true) }),
|
|
24
|
+
z.strictObject({ ...schema_for_inputs(p.inputs).shape, comment: note(false) }),
|
|
25
|
+
]),
|
|
26
|
+
files: (p) => file_inputs(p.inputs),
|
|
27
|
+
summary: (v, p) => ('declined' in v && typeof v.declined === 'string' ? "Couldn't answer" : first_answer(p.inputs, v) ?? 'Responded'),
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","sourceRoot":"","sources":["../../../src/hug/definitions/form.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExF,iEAAiE;AACjE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,UAAU,CAAU,CAAC;AAE9D,uBAAuB;AACvB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;AAO9F,+BAA+B;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAyB;IACnD,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,gIAAgI;IAC7I,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QACnB,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;KACjF,CAAqC;IACtC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,WAAW,CAAC;CACxI,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in hugs' definitions (PLAN-hug-widgets §4.2, §9.1), published as `@getcliqio/cliq-sdk/hugs`: imported by
|
|
3
|
+
* their bundles in cliq-agents and by every agent that asks with them (the gate, `LlmAgent`, `CliAgent`, any
|
|
4
|
+
* `ctx.ask(form, …)`). Browser-safe.
|
|
5
|
+
*/
|
|
6
|
+
export { form, FormParams, FORM_OWN_KEYS } from './form.js';
|
|
7
|
+
export type { FormValues } from './form.js';
|
|
8
|
+
export { approval, ApprovalParams, APPROVAL_OWN_KEYS } from './approval.js';
|
|
9
|
+
export type { ApprovalValues } from './approval.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hug/definitions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC5D,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in hugs' definitions (PLAN-hug-widgets §4.2, §9.1), published as `@getcliqio/cliq-sdk/hugs`: imported by
|
|
3
|
+
* their bundles in cliq-agents and by every agent that asks with them (the gate, `LlmAgent`, `CliAgent`, any
|
|
4
|
+
* `ctx.ask(form, …)`). Browser-safe.
|
|
5
|
+
*/
|
|
6
|
+
export { form, FormParams, FORM_OWN_KEYS } from './form.js';
|
|
7
|
+
export { approval, ApprovalParams, APPROVAL_OWN_KEYS } from './approval.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hug/definitions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hug errors — how a Hug that didn't produce an answer reaches agent code (PLAN-hug-requests
|
|
3
|
+
* §10.6). Uncaught, any of them fails the phase, which fails the run.
|
|
4
|
+
*/
|
|
5
|
+
import type { HugResponse } from './types.js';
|
|
6
|
+
/** Base class for every Hug error. */
|
|
7
|
+
export declare class HugError extends Error {
|
|
8
|
+
/** The Hug, when one was opened. */
|
|
9
|
+
readonly hug_id: string | null;
|
|
10
|
+
constructor(message: string, hug_id: string | null);
|
|
11
|
+
}
|
|
12
|
+
/** Core or cliqd refused to open the Hug (unknown channel, no channels, invalid requested inputs). */
|
|
13
|
+
export declare class HugRefusedError extends HugError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** The Hug expired without the answer the requester's policy needed. */
|
|
17
|
+
export declare class HugExpiredError extends HugError {
|
|
18
|
+
constructor(hug_id: string, message?: string);
|
|
19
|
+
}
|
|
20
|
+
/** The Hug was cancelled (its run ended). */
|
|
21
|
+
export declare class HugCancelledError extends HugError {
|
|
22
|
+
constructor(hug_id: string, message?: string);
|
|
23
|
+
}
|
|
24
|
+
/** The requester's policy saw a rejecting response (e.g. a gate's `reject` or `route:<t>` decision). */
|
|
25
|
+
export declare class HugRejectedError extends HugError {
|
|
26
|
+
/** The response that rejected. */
|
|
27
|
+
readonly response: HugResponse;
|
|
28
|
+
constructor(hug_id: string, message: string, response: HugResponse);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/hug/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,sCAAsC;AACtC,qBAAa,QAAS,SAAQ,KAAK;IAC/B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAKrD;AAED,sGAAsG;AACtG,qBAAa,eAAgB,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM;CAI9B;AAED,wEAAwE;AACxE,qBAAa,eAAgB,SAAQ,QAAQ;gBAC7B,MAAM,EAAE,MAAM,EAAE,OAAO,SAA4C;CAIlF;AAED,6CAA6C;AAC7C,qBAAa,iBAAkB,SAAQ,QAAQ;gBAC/B,MAAM,EAAE,MAAM,EAAE,OAAO,SAAgC;CAItE;AAED,wGAAwG;AACxG,qBAAa,gBAAiB,SAAQ,QAAQ;IAC1C,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;gBAEnB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW;CAKrE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hug errors — how a Hug that didn't produce an answer reaches agent code (PLAN-hug-requests
|
|
3
|
+
* §10.6). Uncaught, any of them fails the phase, which fails the run.
|
|
4
|
+
*/
|
|
5
|
+
/** Base class for every Hug error. */
|
|
6
|
+
export class HugError extends Error {
|
|
7
|
+
/** The Hug, when one was opened. */
|
|
8
|
+
hug_id;
|
|
9
|
+
constructor(message, hug_id) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'HugError';
|
|
12
|
+
this.hug_id = hug_id;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Core or cliqd refused to open the Hug (unknown channel, no channels, invalid requested inputs). */
|
|
16
|
+
export class HugRefusedError extends HugError {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message, null);
|
|
19
|
+
this.name = 'HugRefusedError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The Hug expired without the answer the requester's policy needed. */
|
|
23
|
+
export class HugExpiredError extends HugError {
|
|
24
|
+
constructor(hug_id, message = `Hug ${hug_id} expired without an answer`) {
|
|
25
|
+
super(message, hug_id);
|
|
26
|
+
this.name = 'HugExpiredError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The Hug was cancelled (its run ended). */
|
|
30
|
+
export class HugCancelledError extends HugError {
|
|
31
|
+
constructor(hug_id, message = `Hug ${hug_id} was cancelled`) {
|
|
32
|
+
super(message, hug_id);
|
|
33
|
+
this.name = 'HugCancelledError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The requester's policy saw a rejecting response (e.g. a gate's `reject` or `route:<t>` decision). */
|
|
37
|
+
export class HugRejectedError extends HugError {
|
|
38
|
+
/** The response that rejected. */
|
|
39
|
+
response;
|
|
40
|
+
constructor(hug_id, message, response) {
|
|
41
|
+
super(message, hug_id);
|
|
42
|
+
this.name = 'HugRejectedError';
|
|
43
|
+
this.response = response;
|
|
44
|
+
}
|
|
45
|
+
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CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file given for a `file` requested input (PLAN-hug-requests §6.6.3, §8.7) — the one rule for what
|
|
3
|
+
* it may be, applied wherever a file arrives: CliqHub Core on upload, cliqd for a local answer, and
|
|
4
|
+
* the CLI before it copies one. Pure (no Node APIs), so the browser could use it too.
|
|
5
|
+
*
|
|
6
|
+
* - size: at most the input's `max_bytes`;
|
|
7
|
+
* - type: its declared type or its extension must match an `accept` entry (`application/pdf`,
|
|
8
|
+
* `image/*`, `.md`); a program is accepted only when an entry names its type; recognisable
|
|
9
|
+
* leading bytes must agree with an accepted type (a renamed program isn't taken as a PDF).
|
|
10
|
+
*/
|
|
11
|
+
import type { RequestedInput } from './requested_inputs.js';
|
|
12
|
+
/** How many leading bytes {@link file_accept_problem} looks at. */
|
|
13
|
+
export declare const FILE_SNIFF_BYTES = 16;
|
|
14
|
+
/** The usual type for a file name's extension (`application/octet-stream` when unknown). */
|
|
15
|
+
export declare function file_type_from_name(name: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Why a file fails an `accept` list, or null.
|
|
18
|
+
*
|
|
19
|
+
* @param declared_type - The type it was sent as (an upload's Content-Type; for a local file,
|
|
20
|
+
* {@link file_type_from_name}).
|
|
21
|
+
* @param head - Its first {@link FILE_SNIFF_BYTES} bytes (fewer for a short file).
|
|
22
|
+
*/
|
|
23
|
+
export declare function file_accept_problem(accept: readonly string[], name: string, declared_type: string, head: Uint8Array): string | null;
|
|
24
|
+
/** Why a file is too large for a `file` input, or null. */
|
|
25
|
+
export declare function file_size_problem(input: Extract<RequestedInput, {
|
|
26
|
+
type: 'file';
|
|
27
|
+
}>, name: string, size: number): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Why a file can't be the value of a `file` input, or null — size, then type.
|
|
30
|
+
*
|
|
31
|
+
* @param file.type - Its declared type; omitted for a local file (taken from its name).
|
|
32
|
+
*/
|
|
33
|
+
export declare function file_problem(input: Extract<RequestedInput, {
|
|
34
|
+
type: 'file';
|
|
35
|
+
}>, file: {
|
|
36
|
+
name: string;
|
|
37
|
+
size: number;
|
|
38
|
+
head: Uint8Array;
|
|
39
|
+
type?: string;
|
|
40
|
+
}): string | null;
|
|
41
|
+
//# sourceMappingURL=file_checks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file_checks.d.ts","sourceRoot":"","sources":["../../src/hug/file_checks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAgCnC,4FAA4F;AAC5F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAeD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAcnI;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG7H;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAKnK"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file given for a `file` requested input (PLAN-hug-requests §6.6.3, §8.7) — the one rule for what
|
|
3
|
+
* it may be, applied wherever a file arrives: CliqHub Core on upload, cliqd for a local answer, and
|
|
4
|
+
* the CLI before it copies one. Pure (no Node APIs), so the browser could use it too.
|
|
5
|
+
*
|
|
6
|
+
* - size: at most the input's `max_bytes`;
|
|
7
|
+
* - type: its declared type or its extension must match an `accept` entry (`application/pdf`,
|
|
8
|
+
* `image/*`, `.md`); a program is accepted only when an entry names its type; recognisable
|
|
9
|
+
* leading bytes must agree with an accepted type (a renamed program isn't taken as a PDF).
|
|
10
|
+
*/
|
|
11
|
+
/** How many leading bytes {@link file_accept_problem} looks at. */
|
|
12
|
+
export const FILE_SNIFF_BYTES = 16;
|
|
13
|
+
/** Leading bytes of common types, and of programs (never accepted under another type). */
|
|
14
|
+
const SIGNATURES = [
|
|
15
|
+
{ type: 'application/pdf', bytes: [0x25, 0x50, 0x44, 0x46] },
|
|
16
|
+
{ type: 'image/png', bytes: [0x89, 0x50, 0x4e, 0x47] },
|
|
17
|
+
{ type: 'image/jpeg', bytes: [0xff, 0xd8, 0xff] },
|
|
18
|
+
{ type: 'image/gif', bytes: [0x47, 0x49, 0x46, 0x38] },
|
|
19
|
+
{ type: 'application/zip', bytes: [0x50, 0x4b, 0x03, 0x04] },
|
|
20
|
+
{ type: 'application/x-msdownload', bytes: [0x4d, 0x5a], executable: true },
|
|
21
|
+
{ type: 'application/x-executable', bytes: [0x7f, 0x45, 0x4c, 0x46], executable: true },
|
|
22
|
+
{ type: 'application/x-mach-binary', bytes: [0xcf, 0xfa, 0xed, 0xfe], executable: true },
|
|
23
|
+
];
|
|
24
|
+
/** The type of a file known only by name (a local file): its extension's usual type. */
|
|
25
|
+
const TYPE_BY_EXTENSION = {
|
|
26
|
+
'.pdf': 'application/pdf', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif',
|
|
27
|
+
'.webp': 'image/webp', '.svg': 'image/svg+xml', '.txt': 'text/plain', '.md': 'text/markdown', '.csv': 'text/csv',
|
|
28
|
+
'.json': 'application/json', '.yaml': 'application/yaml', '.yml': 'application/yaml', '.xml': 'application/xml',
|
|
29
|
+
'.html': 'text/html', '.htm': 'text/html', '.zip': 'application/zip', '.gz': 'application/gzip',
|
|
30
|
+
'.doc': 'application/msword', '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
31
|
+
'.xls': 'application/vnd.ms-excel', '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
32
|
+
'.ppt': 'application/vnd.ms-powerpoint', '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
33
|
+
};
|
|
34
|
+
/** A file name's extension, lowercased (`.pdf`), or `''`. */
|
|
35
|
+
function extension(name) {
|
|
36
|
+
const base = name.slice(Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')) + 1);
|
|
37
|
+
const dot = base.lastIndexOf('.');
|
|
38
|
+
return dot > 0 ? base.slice(dot).toLowerCase() : '';
|
|
39
|
+
}
|
|
40
|
+
/** The usual type for a file name's extension (`application/octet-stream` when unknown). */
|
|
41
|
+
export function file_type_from_name(name) {
|
|
42
|
+
return TYPE_BY_EXTENSION[extension(name)] ?? 'application/octet-stream';
|
|
43
|
+
}
|
|
44
|
+
/** Whether a MIME type matches an `accept` entry (`image/*`, `application/pdf`). */
|
|
45
|
+
function mime_matches(entry, type) {
|
|
46
|
+
const e = entry.toLowerCase();
|
|
47
|
+
const t = type.toLowerCase().split(';')[0].trim();
|
|
48
|
+
return e.endsWith('/*') ? t.startsWith(e.slice(0, -1)) : e === t;
|
|
49
|
+
}
|
|
50
|
+
/** The type a file's leading bytes say it is, when recognisable. */
|
|
51
|
+
function sniff(head) {
|
|
52
|
+
const hit = SIGNATURES.find((s) => s.bytes.every((b, i) => head[i] === b));
|
|
53
|
+
return hit ? { type: hit.type, executable: Boolean(hit.executable) } : null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Why a file fails an `accept` list, or null.
|
|
57
|
+
*
|
|
58
|
+
* @param declared_type - The type it was sent as (an upload's Content-Type; for a local file,
|
|
59
|
+
* {@link file_type_from_name}).
|
|
60
|
+
* @param head - Its first {@link FILE_SNIFF_BYTES} bytes (fewer for a short file).
|
|
61
|
+
*/
|
|
62
|
+
export function file_accept_problem(accept, name, declared_type, head) {
|
|
63
|
+
const ext = extension(name);
|
|
64
|
+
const types = accept.filter((a) => a.includes('/'));
|
|
65
|
+
const exts = accept.filter((a) => a.startsWith('.')).map((a) => a.toLowerCase());
|
|
66
|
+
if (!(types.some((t) => mime_matches(t, declared_type)) || (ext !== '' && exts.includes(ext)))) {
|
|
67
|
+
return `${name} is not an accepted type (${accept.join(', ')})`;
|
|
68
|
+
}
|
|
69
|
+
const sniffed = sniff(head);
|
|
70
|
+
if (!sniffed)
|
|
71
|
+
return null;
|
|
72
|
+
if (sniffed.executable && !types.some((t) => mime_matches(t, sniffed.type)))
|
|
73
|
+
return `${name} is a program, not an accepted type`;
|
|
74
|
+
if (types.length > 0 && !types.some((t) => mime_matches(t, sniffed.type)) && !exts.includes(ext)) {
|
|
75
|
+
return `${name}'s content is ${sniffed.type}, not an accepted type`;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/** Why a file is too large for a `file` input, or null. */
|
|
80
|
+
export function file_size_problem(input, name, size) {
|
|
81
|
+
if (input.max_bytes === undefined || size <= input.max_bytes)
|
|
82
|
+
return null;
|
|
83
|
+
return `${name} is larger than ${format_limit(input.max_bytes)}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Why a file can't be the value of a `file` input, or null — size, then type.
|
|
87
|
+
*
|
|
88
|
+
* @param file.type - Its declared type; omitted for a local file (taken from its name).
|
|
89
|
+
*/
|
|
90
|
+
export function file_problem(input, file) {
|
|
91
|
+
const too_big = file_size_problem(input, file.name, file.size);
|
|
92
|
+
if (too_big)
|
|
93
|
+
return too_big;
|
|
94
|
+
if (!input.accept?.length)
|
|
95
|
+
return null;
|
|
96
|
+
return file_accept_problem(input.accept, file.name, file.type ?? file_type_from_name(file.name), file.head);
|
|
97
|
+
}
|
|
98
|
+
function format_limit(bytes) {
|
|
99
|
+
if (bytes >= 1024 * 1024)
|
|
100
|
+
return `${+(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
101
|
+
if (bytes >= 1024)
|
|
102
|
+
return `${+(bytes / 1024).toFixed(1)} KB`;
|
|
103
|
+
return `${bytes} bytes`;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=file_checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file_checks.js","sourceRoot":"","sources":["../../src/hug/file_checks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,mEAAmE;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,0FAA0F;AAC1F,MAAM,UAAU,GAAwE;IACpF,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;IAC5D,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;IACjD,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,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I;QAAE,OAAO,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,OAAO,GAAG,KAAK,QAAQ,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hug files (PLAN-hug-requests Step 11): the run's catalog of files people sent in Hugs, which of
|
|
3
|
+
* them a selector picks, and fetching them through cliqd.
|
|
4
|
+
*
|
|
5
|
+
* Files stay where they were stored — R2 for a CliqHub Hug, cliqd's local store for a terminal one —
|
|
6
|
+
* and everything else holds references. When a phase starts, cliqd writes the run's catalog
|
|
7
|
+
* (references only) to `$CLIQ_RUN_DIR/hug-files.json`; `ctx.hug_files` and `cliq hug files` both
|
|
8
|
+
* read it. A file is read through cliqd's `/v1/artifacts/download`, whichever store it is in.
|
|
9
|
+
*/
|
|
10
|
+
import { Readable } from 'node:stream';
|
|
11
|
+
import type { FileValue } from './requested_inputs.js';
|
|
12
|
+
import type { HugResponder, HugResponse, HugSpec } from './types.js';
|
|
13
|
+
/** The catalog's file name in the run's folder (`$CLIQ_RUN_DIR`). */
|
|
14
|
+
export declare const HUG_FILES_CATALOG = "hug-files.json";
|
|
15
|
+
/** The file `save_hug_files` writes beside the files it saved. */
|
|
16
|
+
export declare const HUG_FILES_INDEX = "files.json";
|
|
17
|
+
/** Where the files people sent in Hugs are kept, relative to the workspace (cliqd keeps a Hug's files there too). */
|
|
18
|
+
export declare const HUG_DIR: string;
|
|
19
|
+
/** How long a download keeps retrying while cliqd or CliqHub can't be reached. */
|
|
20
|
+
export declare const HUG_FILE_RETRY_MS: number;
|
|
21
|
+
/** One file someone sent in a Hug: the reference, and which review, round and person it came from. */
|
|
22
|
+
export interface HugFileEntry extends FileValue {
|
|
23
|
+
readonly phase: string;
|
|
24
|
+
/** The round, counted from 1: the phase's iteration (a review sent back and asked again is the next round). */
|
|
25
|
+
readonly round: number;
|
|
26
|
+
readonly hug_id: string;
|
|
27
|
+
/** The requested input it answered. */
|
|
28
|
+
readonly input: string;
|
|
29
|
+
readonly responder: HugResponder;
|
|
30
|
+
/** The response's `decision` value (a gate's), or null. */
|
|
31
|
+
readonly decision: string | null;
|
|
32
|
+
readonly response_seq: number;
|
|
33
|
+
/** ISO timestamp. */
|
|
34
|
+
readonly received_at: string;
|
|
35
|
+
/** False once the same person changed their answer (the newest answer wins). */
|
|
36
|
+
readonly current: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** A Hug of the run, files or not — so "the latest round" is the latest review, not the latest file. */
|
|
39
|
+
export interface HugRound {
|
|
40
|
+
readonly hug_id: string;
|
|
41
|
+
readonly phase: string;
|
|
42
|
+
readonly round: number;
|
|
43
|
+
readonly status: string;
|
|
44
|
+
}
|
|
45
|
+
/** `$CLIQ_RUN_DIR/hug-files.json`. */
|
|
46
|
+
export interface HugFilesCatalog {
|
|
47
|
+
readonly run_id: string;
|
|
48
|
+
/** ISO timestamp. */
|
|
49
|
+
readonly written_at: string;
|
|
50
|
+
readonly hugs: readonly HugRound[];
|
|
51
|
+
readonly files: readonly HugFileEntry[];
|
|
52
|
+
}
|
|
53
|
+
/** Which files: a phase's input, by default the latest round's current files from everyone. */
|
|
54
|
+
export interface HugFileSelector {
|
|
55
|
+
readonly phase: string;
|
|
56
|
+
readonly input: string;
|
|
57
|
+
/** `latest` (default), `all`, or a round number. */
|
|
58
|
+
readonly round?: 'latest' | 'all' | number;
|
|
59
|
+
/** A responder's name or user id (default: everyone). */
|
|
60
|
+
readonly responder?: string;
|
|
61
|
+
/** Include files whose sender later changed their answer (default: no). */
|
|
62
|
+
readonly include_replaced?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** How a file is fetched from cliqd: retry window, and headers (a remote cliqd's `Authorization`). */
|
|
65
|
+
export interface HugFileFetchOptions {
|
|
66
|
+
/** Default {@link HUG_FILE_RETRY_MS}. */
|
|
67
|
+
readonly retry_ms?: number;
|
|
68
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
69
|
+
}
|
|
70
|
+
/** A file written to disk, checked against its reference. */
|
|
71
|
+
export interface SavedHugFile {
|
|
72
|
+
readonly path: string;
|
|
73
|
+
readonly size: number;
|
|
74
|
+
readonly sha256: string;
|
|
75
|
+
}
|
|
76
|
+
/** Read the run's catalog; an empty one when cliqd hasn't written it (no Hug has files). */
|
|
77
|
+
export declare function read_hug_files_catalog(run_dir?: string | undefined): HugFilesCatalog;
|
|
78
|
+
/** The files a selector picks, oldest round first, then in the order people answered. */
|
|
79
|
+
export declare function select_hug_files(catalog: HugFilesCatalog, selector: HugFileSelector): HugFileEntry[];
|
|
80
|
+
/** Each phase's inputs that have files, for a message when a selector names one that has none. */
|
|
81
|
+
export declare function hug_file_inputs(catalog: HugFilesCatalog): Array<{
|
|
82
|
+
phase: string;
|
|
83
|
+
input: string;
|
|
84
|
+
files: number;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* A stored file's bytes, through cliqd (R2 or its local store). A connection failure or a 5xx is
|
|
88
|
+
* retried with backoff for up to {@link HUG_FILE_RETRY_MS}; cliqd's other answers are thrown.
|
|
89
|
+
*/
|
|
90
|
+
export declare function open_hug_file(daemon_url: string, ref: Pick<FileValue, 'artifact_id'>, opts?: HugFileFetchOptions): Promise<Readable>;
|
|
91
|
+
/**
|
|
92
|
+
* Save a stored file to `dest`, checking its size and sha256 against the reference. Written to a
|
|
93
|
+
* temporary name and renamed once complete, so `dest` is never a partial file.
|
|
94
|
+
*/
|
|
95
|
+
export declare function download_hug_file(daemon_url: string, ref: FileValue, dest: string, opts?: HugFileFetchOptions): Promise<SavedHugFile>;
|
|
96
|
+
/** `dest` resolved inside `root`; throws when it would leave it. */
|
|
97
|
+
export declare function path_inside(root: string, dest: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Save the picked files into `dir` as `<responder>-<file name>` (a clash gets `-2`, `-3`, …) and
|
|
100
|
+
* write `dir/files.json`: each saved file's catalog entry with its `file` name in `dir`. No files:
|
|
101
|
+
* an empty `dir` and an empty `files.json`.
|
|
102
|
+
*
|
|
103
|
+
* @returns the entries as written to `files.json`
|
|
104
|
+
*/
|
|
105
|
+
export declare function save_hug_files(daemon_url: string, entries: readonly HugFileEntry[], dir: string, opts?: HugFileFetchOptions): Promise<Array<HugFileEntry & {
|
|
106
|
+
file: string;
|
|
107
|
+
}>>;
|
|
108
|
+
/** A file someone sent, as a model sees it once saved: where it is in the workspace, or why it isn't there. */
|
|
109
|
+
export type SavedAnswerFile = {
|
|
110
|
+
readonly name: string;
|
|
111
|
+
readonly size: number;
|
|
112
|
+
readonly content_type: string;
|
|
113
|
+
readonly path: string;
|
|
114
|
+
} | {
|
|
115
|
+
readonly name: string;
|
|
116
|
+
readonly error: string;
|
|
117
|
+
};
|
|
118
|
+
/** Saves one file at `dest` (`ctx.download` with a destination). */
|
|
119
|
+
export type SaveHugFile = (ref: FileValue, dest: string) => Promise<SavedHugFile>;
|
|
120
|
+
/**
|
|
121
|
+
* An answer's values with each file someone sent saved in the workspace, at
|
|
122
|
+
* `.cliq/hugs/<hug_id>/<response_id>/<input>/<name>`, and replaced by where it is (relative to the
|
|
123
|
+
* workspace) — so a model reads it with its file tools instead of getting a reference it can't use.
|
|
124
|
+
* The Hug's upload slots (`files`) say which keys hold files. A file already there (same size and sha256) isn't
|
|
125
|
+
* fetched again (a resume can repeat); one that can't be saved is replaced by why, and the rest go
|
|
126
|
+
* on. The first save writes `.cliq/.gitignore`, so nothing cliq keeps in the workspace is committed.
|
|
127
|
+
*
|
|
128
|
+
* @returns the values, and whether any file was saved
|
|
129
|
+
*/
|
|
130
|
+
export declare function save_answer_files(save: SaveHugFile, hug: {
|
|
131
|
+
readonly id: string;
|
|
132
|
+
readonly spec?: HugSpec;
|
|
133
|
+
}, response: HugResponse, workspace: string): Promise<{
|
|
134
|
+
values: Record<string, unknown>;
|
|
135
|
+
saved: boolean;
|
|
136
|
+
}>;
|
|
137
|
+
//# sourceMappingURL=files.d.ts.map
|