@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,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `define_hug` — a hug's definition (PLAN-hug-widgets §9.2.0): its name, what it is asked (`params`), what it answers
|
|
3
|
+
* (`values`), its upload slots (`files`) and its one-line `summary`. Written once in a hug's `hug.ts` and imported by
|
|
4
|
+
* its frontend (`mount_hug` checks every change with it) and by agent code (`ctx.ask` checks every response with it);
|
|
5
|
+
* compiled into the bundle's `definition.mjs` so generic agents can use it too.
|
|
6
|
+
*
|
|
7
|
+
* `values`, `files` and `summary` may be functions of `params`, for a hug whose answer depends on what it was asked
|
|
8
|
+
* (`form`'s fields, the gate's `approval` inputs and route choices).
|
|
9
|
+
*
|
|
10
|
+
* Browser-safe and Node-safe: imports only `zod` and the shared problem helpers.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { problems_from_zod } from './problems.js';
|
|
14
|
+
/** A hug's name: lowercase letters, digits and hyphens, starting with a letter (its folder's name). */
|
|
15
|
+
export const HUG_NAME_RE = /^[a-z][a-z0-9-]{0,63}$/;
|
|
16
|
+
/** Longest summary the Hub stores (PLAN-hug-widgets §3.2). */
|
|
17
|
+
export const MAX_SUMMARY_LENGTH = 120;
|
|
18
|
+
/** A file reference in an answer: the id the upload returned (metadata may ride along). */
|
|
19
|
+
export const FileRefSchema = z.looseObject({
|
|
20
|
+
artifact_id: z.string({ error: 'must be an uploaded file' }).min(1, 'must be an uploaded file'),
|
|
21
|
+
});
|
|
22
|
+
/** Most files one `multiple` upload slot takes. */
|
|
23
|
+
export const MAX_FILES_PER_SLOT = 10;
|
|
24
|
+
/**
|
|
25
|
+
* An upload field for a definition's `values`. Its key becomes an upload slot of the Hug (`files`), so nobody declares
|
|
26
|
+
* upload keys separately.
|
|
27
|
+
*
|
|
28
|
+
* @param opts - What it accepts; `multiple` for a list of files; `optional` when an answer may leave it out.
|
|
29
|
+
*/
|
|
30
|
+
export function file(opts = {}) {
|
|
31
|
+
const meta = {
|
|
32
|
+
...(opts.accept ? { accept: opts.accept } : {}),
|
|
33
|
+
...(opts.max_bytes ? { max_bytes: opts.max_bytes } : {}),
|
|
34
|
+
...(opts.multiple ? { multiple: true } : {}),
|
|
35
|
+
};
|
|
36
|
+
const least = opts.optional ? 0 : 1;
|
|
37
|
+
const many = z.array(FileRefSchema, { error: 'must be a list of uploaded files' })
|
|
38
|
+
.max(MAX_FILES_PER_SLOT, `takes at most ${MAX_FILES_PER_SLOT} files`)
|
|
39
|
+
.min(least, 'required');
|
|
40
|
+
const one = opts.multiple ? many : FileRefSchema;
|
|
41
|
+
const marked = one.meta({ cliq_file: meta });
|
|
42
|
+
return (opts.optional ? marked.optional() : marked);
|
|
43
|
+
}
|
|
44
|
+
/** The `file()` metadata on a field (looking through `optional`/`nullable`/`default`), or null. */
|
|
45
|
+
function file_meta(schema) {
|
|
46
|
+
let s = schema;
|
|
47
|
+
let required = true;
|
|
48
|
+
for (let depth = 0; depth < 5; depth++) {
|
|
49
|
+
const meta = s.meta()?.cliq_file;
|
|
50
|
+
if (meta)
|
|
51
|
+
return { meta, required };
|
|
52
|
+
const inner = s._zod.def;
|
|
53
|
+
if (!inner.innerType)
|
|
54
|
+
return null;
|
|
55
|
+
if (['optional', 'nullable', 'default', 'prefault'].includes(inner.type))
|
|
56
|
+
required = false;
|
|
57
|
+
s = inner.innerType;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/** The upload slots of a values schema: its top-level fields made with `file()`. */
|
|
62
|
+
export function file_slots_of(values) {
|
|
63
|
+
if (!(values instanceof z.ZodObject))
|
|
64
|
+
return [];
|
|
65
|
+
const slots = [];
|
|
66
|
+
for (const [name, field] of Object.entries(values.shape)) {
|
|
67
|
+
const found = file_meta(field);
|
|
68
|
+
if (found)
|
|
69
|
+
slots.push({ name, ...found.meta, required: found.required });
|
|
70
|
+
}
|
|
71
|
+
return slots;
|
|
72
|
+
}
|
|
73
|
+
/** The text cut to `max` characters, with an ellipsis when cut. */
|
|
74
|
+
function clip(text, max) {
|
|
75
|
+
const one_line = text.replace(/\s+/g, ' ').trim();
|
|
76
|
+
return one_line.length <= max ? one_line : `${one_line.slice(0, max - 1)}…`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Define a hug.
|
|
80
|
+
*
|
|
81
|
+
* @param spec - The hug's name, params, values, and optionally its title, description, files and summary.
|
|
82
|
+
* @throws Error when the name isn't a hug name.
|
|
83
|
+
*/
|
|
84
|
+
export function define_hug(spec) {
|
|
85
|
+
if (!HUG_NAME_RE.test(spec.name))
|
|
86
|
+
throw new Error(`'${spec.name}' is not a hug name (lowercase letters, digits and hyphens, starting with a letter)`);
|
|
87
|
+
const values_schema = (params) => (typeof spec.values === 'function' ? spec.values(params) : spec.values);
|
|
88
|
+
const files = (params) => {
|
|
89
|
+
if (spec.files)
|
|
90
|
+
return [...(typeof spec.files === 'function' ? spec.files(params) : spec.files)];
|
|
91
|
+
return file_slots_of(values_schema(params));
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
name: spec.name,
|
|
95
|
+
title: spec.title ?? spec.name,
|
|
96
|
+
description: spec.description ?? '',
|
|
97
|
+
params: spec.params,
|
|
98
|
+
values_schema,
|
|
99
|
+
files,
|
|
100
|
+
summary: (values, params) => clip(spec.summary ? spec.summary(values, params) : 'Responded', MAX_SUMMARY_LENGTH),
|
|
101
|
+
check_params(raw) {
|
|
102
|
+
const parsed = spec.params.safeParse(raw ?? {});
|
|
103
|
+
return parsed.success ? { ok: true, value: parsed.data } : { ok: false, problems: problems_from_zod(parsed.error) };
|
|
104
|
+
},
|
|
105
|
+
check(raw, params) {
|
|
106
|
+
const parsed = values_schema(params).safeParse(raw);
|
|
107
|
+
return parsed.success ? { ok: true, value: parsed.data } : { ok: false, problems: problems_from_zod(parsed.error) };
|
|
108
|
+
},
|
|
109
|
+
describe() {
|
|
110
|
+
return {
|
|
111
|
+
name: spec.name,
|
|
112
|
+
title: spec.title ?? spec.name,
|
|
113
|
+
description: spec.description ?? '',
|
|
114
|
+
params_schema: z.toJSONSchema(spec.params, { unrepresentable: 'any', io: 'input' }),
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/hug/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAgB,MAAM,eAAe,CAAC;AAEhE,uGAAuG;AACvG,MAAM,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gBACH,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI;gBAC9B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;gBACnC,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,CAA4B;aACjH,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `approval` — the built-in hug that approves or rejects the work (PLAN-hug-widgets §10.1); the Hug gate always asks
|
|
3
|
+
* with it. A gate configures it through its params: `review.inputs` → `inputs` (the fields approving requires),
|
|
4
|
+
* `route_targets` → `reject_choices` ("Send back to …"), `review.params` → the labels and `show_comment`.
|
|
5
|
+
*
|
|
6
|
+
* Answer: `{ decision: 'approve', …one key per input (required ones enforced), comment? }`, or
|
|
7
|
+
* `{ decision: 'reject', reason, choice? }` — a rejection never needs the inputs. The same rules as today's
|
|
8
|
+
* `approval_v1` (the parity is tested).
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
/** The answer keys `approval` adds itself; inputs can't use them. */
|
|
12
|
+
export declare const APPROVAL_OWN_KEYS: readonly ["decision", "reason", "choice", "comment"];
|
|
13
|
+
/** `approval`'s params. */
|
|
14
|
+
export declare const ApprovalParams: z.ZodObject<{
|
|
15
|
+
reject_choices: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
16
|
+
value: z.ZodString;
|
|
17
|
+
label: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strict>>>;
|
|
19
|
+
approve_label: z.ZodOptional<z.ZodString>;
|
|
20
|
+
reject_label: z.ZodOptional<z.ZodString>;
|
|
21
|
+
show_comment: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
23
|
+
context: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
24
|
+
type: z.ZodLiteral<"markdown">;
|
|
25
|
+
text: z.ZodString;
|
|
26
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"artifact">;
|
|
28
|
+
artifact_id: z.ZodString;
|
|
29
|
+
label: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
31
|
+
type: z.ZodLiteral<"checks">;
|
|
32
|
+
results: z.ZodArray<z.ZodObject<{
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
ok: z.ZodBoolean;
|
|
35
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
38
|
+
type: z.ZodLiteral<"transcript">;
|
|
39
|
+
turns: z.ZodArray<z.ZodObject<{
|
|
40
|
+
role: z.ZodString;
|
|
41
|
+
content: z.ZodString;
|
|
42
|
+
}, z.core.$strict>>;
|
|
43
|
+
}, z.core.$strict>], "type">>>;
|
|
44
|
+
inputs: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
45
|
+
type: z.ZodLiteral<"text">;
|
|
46
|
+
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
47
|
+
min_length: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
max_length: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
name: z.ZodString;
|
|
50
|
+
label: z.ZodOptional<z.ZodString>;
|
|
51
|
+
help: z.ZodOptional<z.ZodString>;
|
|
52
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
54
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
55
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
56
|
+
type: z.ZodLiteral<"number">;
|
|
57
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
integer: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
name: z.ZodString;
|
|
61
|
+
label: z.ZodOptional<z.ZodString>;
|
|
62
|
+
help: z.ZodOptional<z.ZodString>;
|
|
63
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
65
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
66
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
67
|
+
type: z.ZodLiteral<"boolean">;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
label: z.ZodOptional<z.ZodString>;
|
|
70
|
+
help: z.ZodOptional<z.ZodString>;
|
|
71
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
73
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
74
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
75
|
+
type: z.ZodLiteral<"enum">;
|
|
76
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
77
|
+
value: z.ZodString;
|
|
78
|
+
label: z.ZodOptional<z.ZodString>;
|
|
79
|
+
}, z.core.$strict>>;
|
|
80
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
+
name: z.ZodString;
|
|
82
|
+
label: z.ZodOptional<z.ZodString>;
|
|
83
|
+
help: z.ZodOptional<z.ZodString>;
|
|
84
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
86
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
type: z.ZodLiteral<"file">;
|
|
89
|
+
accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
90
|
+
max_bytes: z.ZodOptional<z.ZodNumber>;
|
|
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>, z.ZodObject<{
|
|
99
|
+
type: z.ZodLiteral<"channel">;
|
|
100
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
name: z.ZodString;
|
|
102
|
+
label: z.ZodOptional<z.ZodString>;
|
|
103
|
+
help: z.ZodOptional<z.ZodString>;
|
|
104
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
105
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
106
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
107
|
+
}, z.core.$strict>], "type">>>;
|
|
108
|
+
}, z.core.$strict>;
|
|
109
|
+
/** `approval`'s params. */
|
|
110
|
+
export type ApprovalParams = z.infer<typeof ApprovalParams>;
|
|
111
|
+
/** An `approval` answer. */
|
|
112
|
+
export type ApprovalValues = ({
|
|
113
|
+
decision: 'approve';
|
|
114
|
+
comment?: string | null;
|
|
115
|
+
} & Record<string, unknown>) | {
|
|
116
|
+
decision: 'reject';
|
|
117
|
+
reason: string;
|
|
118
|
+
choice?: string | null;
|
|
119
|
+
};
|
|
120
|
+
/** The built-in `approval` hug. */
|
|
121
|
+
export declare const approval: import("../define.js").HugDefinition<{
|
|
122
|
+
inputs: ({
|
|
123
|
+
type: "text";
|
|
124
|
+
name: string;
|
|
125
|
+
multiline?: boolean | undefined;
|
|
126
|
+
min_length?: number | undefined;
|
|
127
|
+
max_length?: number | undefined;
|
|
128
|
+
label?: string | undefined;
|
|
129
|
+
help?: string | undefined;
|
|
130
|
+
required?: boolean | undefined;
|
|
131
|
+
default?: unknown;
|
|
132
|
+
ui?: Record<string, unknown> | undefined;
|
|
133
|
+
} | {
|
|
134
|
+
type: "number";
|
|
135
|
+
name: string;
|
|
136
|
+
min?: number | undefined;
|
|
137
|
+
max?: number | undefined;
|
|
138
|
+
integer?: boolean | undefined;
|
|
139
|
+
label?: string | undefined;
|
|
140
|
+
help?: string | undefined;
|
|
141
|
+
required?: boolean | undefined;
|
|
142
|
+
default?: unknown;
|
|
143
|
+
ui?: Record<string, unknown> | undefined;
|
|
144
|
+
} | {
|
|
145
|
+
type: "boolean";
|
|
146
|
+
name: string;
|
|
147
|
+
label?: string | undefined;
|
|
148
|
+
help?: string | undefined;
|
|
149
|
+
required?: boolean | undefined;
|
|
150
|
+
default?: unknown;
|
|
151
|
+
ui?: Record<string, unknown> | undefined;
|
|
152
|
+
} | {
|
|
153
|
+
type: "enum";
|
|
154
|
+
choices: {
|
|
155
|
+
value: string;
|
|
156
|
+
label?: string | undefined;
|
|
157
|
+
}[];
|
|
158
|
+
name: string;
|
|
159
|
+
multiple?: boolean | undefined;
|
|
160
|
+
label?: string | undefined;
|
|
161
|
+
help?: string | undefined;
|
|
162
|
+
required?: boolean | undefined;
|
|
163
|
+
default?: unknown;
|
|
164
|
+
ui?: Record<string, unknown> | undefined;
|
|
165
|
+
} | {
|
|
166
|
+
type: "file";
|
|
167
|
+
name: string;
|
|
168
|
+
accept?: string[] | undefined;
|
|
169
|
+
max_bytes?: number | undefined;
|
|
170
|
+
multiple?: boolean | undefined;
|
|
171
|
+
label?: string | undefined;
|
|
172
|
+
help?: string | undefined;
|
|
173
|
+
required?: boolean | undefined;
|
|
174
|
+
default?: unknown;
|
|
175
|
+
ui?: Record<string, unknown> | undefined;
|
|
176
|
+
} | {
|
|
177
|
+
type: "channel";
|
|
178
|
+
name: string;
|
|
179
|
+
multiple?: boolean | undefined;
|
|
180
|
+
label?: string | undefined;
|
|
181
|
+
help?: string | undefined;
|
|
182
|
+
required?: boolean | undefined;
|
|
183
|
+
default?: unknown;
|
|
184
|
+
ui?: Record<string, unknown> | undefined;
|
|
185
|
+
})[];
|
|
186
|
+
reject_choices?: {
|
|
187
|
+
value: string;
|
|
188
|
+
label?: string | undefined;
|
|
189
|
+
}[] | undefined;
|
|
190
|
+
approve_label?: string | undefined;
|
|
191
|
+
reject_label?: string | undefined;
|
|
192
|
+
show_comment?: boolean | undefined;
|
|
193
|
+
prompt?: string | undefined;
|
|
194
|
+
context?: ({
|
|
195
|
+
type: "markdown";
|
|
196
|
+
text: string;
|
|
197
|
+
} | {
|
|
198
|
+
type: "artifact";
|
|
199
|
+
artifact_id: string;
|
|
200
|
+
label?: string | undefined;
|
|
201
|
+
} | {
|
|
202
|
+
type: "checks";
|
|
203
|
+
results: {
|
|
204
|
+
name: string;
|
|
205
|
+
ok: boolean;
|
|
206
|
+
summary?: string | undefined;
|
|
207
|
+
}[];
|
|
208
|
+
} | {
|
|
209
|
+
type: "transcript";
|
|
210
|
+
turns: {
|
|
211
|
+
role: string;
|
|
212
|
+
content: string;
|
|
213
|
+
}[];
|
|
214
|
+
})[] | undefined;
|
|
215
|
+
}, ApprovalValues>;
|
|
216
|
+
//# sourceMappingURL=approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../../../src/hug/definitions/approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,sDAAuD,CAAC;AAItF,2BAA2B;AAC3B,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBASmB,CAAC;AAC/C,2BAA2B;AAC3B,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D,4BAA4B;AAC5B,MAAM,MAAM,cAAc,GACpB,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC5E;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AASrE,mCAAmC;AACnC,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAenB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `approval` — the built-in hug that approves or rejects the work (PLAN-hug-widgets §10.1); the Hug gate always asks
|
|
3
|
+
* with it. A gate configures it through its params: `review.inputs` → `inputs` (the fields approving requires),
|
|
4
|
+
* `route_targets` → `reject_choices` ("Send back to …"), `review.params` → the labels and `show_comment`.
|
|
5
|
+
*
|
|
6
|
+
* Answer: `{ decision: 'approve', …one key per input (required ones enforced), comment? }`, or
|
|
7
|
+
* `{ decision: 'reject', reason, choice? }` — a rejection never needs the inputs. The same rules as today's
|
|
8
|
+
* `approval_v1` (the parity is tested).
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { define_hug } from '../define.js';
|
|
12
|
+
import { schema_for_inputs } from '../schema_for_inputs.js';
|
|
13
|
+
import { base_params, file_inputs, no_own_keys, note } from './common.js';
|
|
14
|
+
/** The answer keys `approval` adds itself; inputs can't use them. */
|
|
15
|
+
export const APPROVAL_OWN_KEYS = ['decision', 'reason', 'choice', 'comment'];
|
|
16
|
+
const Choice = z.strictObject({ value: z.string().min(1).max(200), label: z.string().max(200).optional() });
|
|
17
|
+
/** `approval`'s params. */
|
|
18
|
+
export const ApprovalParams = z.strictObject({
|
|
19
|
+
...base_params,
|
|
20
|
+
reject_choices: z.array(Choice).max(20).refine((choices) => new Set(choices.map((c) => c.value)).size === choices.length, 'values must be unique').optional(),
|
|
21
|
+
approve_label: z.string().min(1).max(40).optional(),
|
|
22
|
+
reject_label: z.string().min(1).max(40).optional(),
|
|
23
|
+
show_comment: z.boolean().optional(),
|
|
24
|
+
}).superRefine(no_own_keys(APPROVAL_OWN_KEYS));
|
|
25
|
+
/** The choice schema for these params: one of `reject_choices`, or none when none are offered. */
|
|
26
|
+
function choice_schema(p) {
|
|
27
|
+
const values = (p.reject_choices ?? []).map((c) => c.value);
|
|
28
|
+
if (values.length === 0)
|
|
29
|
+
return z.null({ error: 'must be one of (none offered)' }).optional();
|
|
30
|
+
return z.enum(values, { error: `must be one of ${values.join(', ')}` }).nullish();
|
|
31
|
+
}
|
|
32
|
+
/** The built-in `approval` hug. */
|
|
33
|
+
export const approval = define_hug({
|
|
34
|
+
name: 'approval',
|
|
35
|
+
title: 'Approval',
|
|
36
|
+
description: 'Asks people to approve the work (filling in any fields approving requires) or reject it with a reason and, when offered, where to send it back.',
|
|
37
|
+
params: ApprovalParams,
|
|
38
|
+
values: (p) => z.discriminatedUnion('decision', [
|
|
39
|
+
z.strictObject({ ...schema_for_inputs(p.inputs).shape, decision: z.literal('approve'), comment: note(false) }),
|
|
40
|
+
z.strictObject({ decision: z.literal('reject'), reason: note(true), choice: choice_schema(p) }),
|
|
41
|
+
], { error: 'decision: must be approve or reject' }),
|
|
42
|
+
files: (p) => file_inputs(p.inputs),
|
|
43
|
+
summary: (v, p) => {
|
|
44
|
+
if (v.decision === 'approve')
|
|
45
|
+
return 'Approved';
|
|
46
|
+
const choice = (p.reject_choices ?? []).find((c) => c.value === v.choice);
|
|
47
|
+
return choice ? (choice.label ?? `Rejected — ${choice.value}`) : 'Rejected';
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=approval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../../src/hug/definitions/approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE1E,qEAAqE;AACrE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAEtF,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAE5G,2BAA2B;AAC3B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,YAAY,CAAC;IACzC,GAAG,WAAW;IACd,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAC1C,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,MAAM,EACzE,uBAAuB,CAC1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CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9G,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;KAClG,EAAE,EAAE,KAAK,EAAE,qCAAqC,EAAE,CAAyC;IAC5F,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACd,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,UAAU,CAAC;QAChD,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;QAC1E,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,cAAc,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAChF,CAAC;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pieces the built-in definitions share (PLAN-hug-widgets §9.2.0): their common params, notes (a comment, a reason),
|
|
3
|
+
* the "inputs can't use our own keys" rule, and the first-answer summary.
|
|
4
|
+
*
|
|
5
|
+
* Browser-safe: imports only `zod` and the shared hug modules.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { type RequestedInput } from '../requested_inputs.js';
|
|
9
|
+
/** Longest prompt (markdown). */
|
|
10
|
+
export declare const MAX_PROMPT_LENGTH = 20000;
|
|
11
|
+
/** Longest free-text answer a built-in hug adds itself (a reason, a comment). */
|
|
12
|
+
export declare const MAX_NOTE_LENGTH = 20000;
|
|
13
|
+
/** Params every built-in hug takes: what is asked, what is shown with it, and the fields. */
|
|
14
|
+
export declare const base_params: {
|
|
15
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
16
|
+
context: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
17
|
+
type: z.ZodLiteral<"markdown">;
|
|
18
|
+
text: z.ZodString;
|
|
19
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
20
|
+
type: z.ZodLiteral<"artifact">;
|
|
21
|
+
artifact_id: z.ZodString;
|
|
22
|
+
label: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
type: z.ZodLiteral<"checks">;
|
|
25
|
+
results: z.ZodArray<z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
ok: z.ZodBoolean;
|
|
28
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strict>>;
|
|
30
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
31
|
+
type: z.ZodLiteral<"transcript">;
|
|
32
|
+
turns: z.ZodArray<z.ZodObject<{
|
|
33
|
+
role: z.ZodString;
|
|
34
|
+
content: z.ZodString;
|
|
35
|
+
}, z.core.$strict>>;
|
|
36
|
+
}, z.core.$strict>], "type">>>;
|
|
37
|
+
inputs: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
38
|
+
type: z.ZodLiteral<"text">;
|
|
39
|
+
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
min_length: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
max_length: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
label: z.ZodOptional<z.ZodString>;
|
|
44
|
+
help: z.ZodOptional<z.ZodString>;
|
|
45
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
47
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
48
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
49
|
+
type: z.ZodLiteral<"number">;
|
|
50
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
integer: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
+
name: z.ZodString;
|
|
54
|
+
label: z.ZodOptional<z.ZodString>;
|
|
55
|
+
help: z.ZodOptional<z.ZodString>;
|
|
56
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
58
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
59
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
60
|
+
type: z.ZodLiteral<"boolean">;
|
|
61
|
+
name: z.ZodString;
|
|
62
|
+
label: z.ZodOptional<z.ZodString>;
|
|
63
|
+
help: z.ZodOptional<z.ZodString>;
|
|
64
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
66
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
67
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
68
|
+
type: z.ZodLiteral<"enum">;
|
|
69
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
70
|
+
value: z.ZodString;
|
|
71
|
+
label: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$strict>>;
|
|
73
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
74
|
+
name: z.ZodString;
|
|
75
|
+
label: z.ZodOptional<z.ZodString>;
|
|
76
|
+
help: z.ZodOptional<z.ZodString>;
|
|
77
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
79
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
80
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
81
|
+
type: z.ZodLiteral<"file">;
|
|
82
|
+
accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
83
|
+
max_bytes: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
name: z.ZodString;
|
|
86
|
+
label: z.ZodOptional<z.ZodString>;
|
|
87
|
+
help: z.ZodOptional<z.ZodString>;
|
|
88
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
89
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
90
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
91
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"channel">;
|
|
93
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
name: z.ZodString;
|
|
95
|
+
label: z.ZodOptional<z.ZodString>;
|
|
96
|
+
help: z.ZodOptional<z.ZodString>;
|
|
97
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
98
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
99
|
+
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
100
|
+
}, z.core.$strict>], "type">>>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Refuses inputs named like one of the hug's own answer keys.
|
|
104
|
+
*
|
|
105
|
+
* @param own - The keys the hug adds to an answer itself (`comment`, `declined`, …).
|
|
106
|
+
*/
|
|
107
|
+
export declare const no_own_keys: (own: readonly string[]) => (p: {
|
|
108
|
+
inputs: RequestedInput[];
|
|
109
|
+
}, ctx: z.RefinementCtx) => void;
|
|
110
|
+
/** A note: text of at most {@link MAX_NOTE_LENGTH}, trimmed (the checked value has no surrounding spaces); required means not blank. */
|
|
111
|
+
export declare function note(required: boolean): z.ZodType<string | null | undefined>;
|
|
112
|
+
/** The upload slots of requested inputs: their file inputs. */
|
|
113
|
+
export declare function file_inputs(inputs: readonly RequestedInput[]): {
|
|
114
|
+
required: boolean;
|
|
115
|
+
multiple?: boolean | undefined;
|
|
116
|
+
max_bytes?: number | undefined;
|
|
117
|
+
accept?: string[] | undefined;
|
|
118
|
+
name: string;
|
|
119
|
+
}[];
|
|
120
|
+
/** The first answered value that reads as a line (not a file), as today's "others responded" line shows it. */
|
|
121
|
+
export declare function first_answer(inputs: readonly RequestedInput[], values: Record<string, unknown>): string | null;
|
|
122
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/hug/definitions/common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEpF,iCAAiC;AACjC,eAAO,MAAM,iBAAiB,QAAS,CAAC;AACxC,iFAAiF;AACjF,eAAO,MAAM,eAAe,QAAS,CAAC;AAEtC,6FAA6F;AAC7F,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,SAAS,MAAM,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,cAAc,EAAE,CAAA;CAAE,EAAE,KAAK,CAAC,CAAC,aAAa,KAAG,IAI/G,CAAC;AAEF,wIAAwI;AACxI,wBAAgB,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAK5E;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE;;;;;;IAQ5D;AAaD,+GAA+G;AAC/G,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAO9G"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pieces the built-in definitions share (PLAN-hug-widgets §9.2.0): their common params, notes (a comment, a reason),
|
|
3
|
+
* the "inputs can't use our own keys" rule, and the first-answer summary.
|
|
4
|
+
*
|
|
5
|
+
* Browser-safe: imports only `zod` and the shared hug modules.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { ContextSchema } from '../context.js';
|
|
9
|
+
import { RequestedInputsSchema } from '../requested_inputs.js';
|
|
10
|
+
/** Longest prompt (markdown). */
|
|
11
|
+
export const MAX_PROMPT_LENGTH = 20_000;
|
|
12
|
+
/** Longest free-text answer a built-in hug adds itself (a reason, a comment). */
|
|
13
|
+
export const MAX_NOTE_LENGTH = 20_000;
|
|
14
|
+
/** Params every built-in hug takes: what is asked, what is shown with it, and the fields. */
|
|
15
|
+
export const base_params = {
|
|
16
|
+
prompt: z.string().max(MAX_PROMPT_LENGTH).optional(),
|
|
17
|
+
context: ContextSchema.optional(),
|
|
18
|
+
inputs: RequestedInputsSchema.default([]),
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Refuses inputs named like one of the hug's own answer keys.
|
|
22
|
+
*
|
|
23
|
+
* @param own - The keys the hug adds to an answer itself (`comment`, `declined`, …).
|
|
24
|
+
*/
|
|
25
|
+
export const no_own_keys = (own) => (p, ctx) => {
|
|
26
|
+
p.inputs.forEach((input, i) => {
|
|
27
|
+
if (own.includes(input.name))
|
|
28
|
+
ctx.addIssue({ code: 'custom', path: ['inputs', i, 'name'], message: `'${input.name}' is a key of the hug's own` });
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
/** A note: text of at most {@link MAX_NOTE_LENGTH}, trimmed (the checked value has no surrounding spaces); required means not blank. */
|
|
32
|
+
export function note(required) {
|
|
33
|
+
const text = z.string({ error: (i) => (i.input === undefined || i.input === null ? 'required' : 'must be text') })
|
|
34
|
+
.trim()
|
|
35
|
+
.max(MAX_NOTE_LENGTH, `at most ${MAX_NOTE_LENGTH} characters`);
|
|
36
|
+
return required ? text.refine((v) => v !== '', 'required') : text.nullish();
|
|
37
|
+
}
|
|
38
|
+
/** The upload slots of requested inputs: their file inputs. */
|
|
39
|
+
export function file_inputs(inputs) {
|
|
40
|
+
return inputs.filter((i) => i.type === 'file').map((i) => ({
|
|
41
|
+
name: i.name,
|
|
42
|
+
...(i.accept ? { accept: i.accept } : {}),
|
|
43
|
+
...(i.max_bytes ? { max_bytes: i.max_bytes } : {}),
|
|
44
|
+
...(i.multiple ? { multiple: true } : {}),
|
|
45
|
+
required: i.required !== false,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
/** An input's value as words: an enum's choice labels, Yes / No, channels joined, else the text. */
|
|
49
|
+
function value_words(input, value) {
|
|
50
|
+
if (input.type === 'enum') {
|
|
51
|
+
const label = (v) => input.choices.find((c) => c.value === v)?.label ?? String(v);
|
|
52
|
+
return Array.isArray(value) ? value.map(label).join(', ') : label(value);
|
|
53
|
+
}
|
|
54
|
+
if (input.type === 'boolean')
|
|
55
|
+
return value ? 'Yes' : 'No';
|
|
56
|
+
if (Array.isArray(value))
|
|
57
|
+
return value.join(', ');
|
|
58
|
+
return String(value);
|
|
59
|
+
}
|
|
60
|
+
/** The first answered value that reads as a line (not a file), as today's "others responded" line shows it. */
|
|
61
|
+
export function first_answer(inputs, values) {
|
|
62
|
+
for (const input of inputs) {
|
|
63
|
+
const value = values[input.name];
|
|
64
|
+
if (input.type === 'file' || value === undefined || value === null || value === '')
|
|
65
|
+
continue;
|
|
66
|
+
return value_words(input, value);
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/hug/definitions/common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAuB,MAAM,wBAAwB,CAAC;AAEpF,iCAAiC;AACjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACxC,iFAAiF;AACjF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAEtC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;IACpD,OAAO,EAAE,aAAa,CAAC,QAAQ,EAAE;IACjC,MAAM,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;CAC5C,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAsB,EAAE,EAAE,CAAC,CAAC,CAA+B,EAAE,GAAoB,EAAQ,EAAE;IACnH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC1B,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,KAAK,CAA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