@qilin-agent/commands 0.0.0-stage → 3.1.3

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.
@@ -0,0 +1,29 @@
1
+ /* Generated by @qilin-agent/typert-generator from the Host FaceModel — do not edit. */
2
+ import type {
3
+ RemoteResult,
4
+ TypertRemoteContribution,
5
+ } from '@qilin-agent/typert-protocol'
6
+ import type { CommandDescriptor, CommandExecution, CommandSubmitAttachment } from '@qilin-agent/commands/types'
7
+ import type { SessionId } from '@qilin-agent/session/types'
8
+
9
+ declare module '@qilin-agent/typert-protocol' {
10
+ interface TypertRemoteNamespace$636f6d6d616e6473 {
11
+ execute: (agentId: SessionId, line: string, submittedAttachments: readonly CommandSubmitAttachment[], signal?: AbortSignal) => Promise<RemoteResult<CommandExecution | undefined>>
12
+ list: (agentId: SessionId) => Promise<RemoteResult<readonly CommandDescriptor[]>>
13
+ }
14
+ interface TypertRemoteMap {
15
+ 'commands/execute': (agentId: SessionId, line: string, submittedAttachments: readonly CommandSubmitAttachment[], signal?: AbortSignal) => Promise<RemoteResult<CommandExecution | undefined>>
16
+ 'commands/list': (agentId: SessionId) => Promise<RemoteResult<readonly CommandDescriptor[]>>
17
+ }
18
+ interface TypertRemoteNamespaceMap {
19
+ 'commands': TypertRemoteNamespace$636f6d6d616e6473
20
+ }
21
+ interface TypertRemoteScopeMap {
22
+ 'agent:commands/execute': (line: string, submittedAttachments: readonly CommandSubmitAttachment[], signal?: AbortSignal) => Promise<RemoteResult<CommandExecution | undefined>>
23
+ 'agent:commands/list': () => Promise<RemoteResult<readonly CommandDescriptor[]>>
24
+ }
25
+ }
26
+
27
+ export declare const TYPERT_REMOTE: TypertRemoteContribution
28
+ export default TYPERT_REMOTE
29
+ //# sourceMappingURL=typert.remote-client.d.ts.map
@@ -0,0 +1,131 @@
1
+ /* Generated by @qilin-agent/typert-generator from the Host FaceModel — do not edit. */
2
+ import { z } from 'zod'
3
+
4
+ let _qilin_agent_commands_commands_execute_parameter_0$schema$value
5
+ const _qilin_agent_commands_commands_execute_parameter_0$schema = () => (_qilin_agent_commands_commands_execute_parameter_0$schema$value ??= z.intersection(z.string(), z.unknown()))
6
+ let _qilin_agent_commands_commands_execute_parameter_1$schema$value
7
+ const _qilin_agent_commands_commands_execute_parameter_1$schema = () => (_qilin_agent_commands_commands_execute_parameter_1$schema$value ??= z.string())
8
+ let _qilin_agent_commands_commands_execute_parameter_2$schema$value
9
+ const _qilin_agent_commands_commands_execute_parameter_2$schema = () => (_qilin_agent_commands_commands_execute_parameter_2$schema$value ??= z.array(z.union([z.intersection(z.object({
10
+ 'type': z.literal("image").readonly(),
11
+ }), z.object({
12
+ 'mediaType': z.union([z.literal("image/png"), z.literal("image/jpeg"), z.literal("image/webp"), z.literal("image/gif")]),
13
+ 'data': z.string(),
14
+ 'name': z.string().optional(),
15
+ })), z.object({
16
+ 'type': z.literal("file").readonly(),
17
+ 'receiptId': z.string().readonly(),
18
+ })])))
19
+ let _qilin_agent_commands_commands_execute_result$schema$value
20
+ const _qilin_agent_commands_commands_execute_result$schema = () => (_qilin_agent_commands_commands_execute_result$schema$value ??= z.union([z.undefined(), z.object({
21
+ 'commandId': z.intersection(z.string(), z.unknown()).readonly(),
22
+ 'result': z.union([z.object({
23
+ 'kind': z.literal("success").readonly(),
24
+ 'text': z.string().readonly().optional(),
25
+ 'sourceEventSeq': z.intersection(z.number(), z.unknown()).readonly().optional(),
26
+ }), z.object({
27
+ 'kind': z.literal("error").readonly(),
28
+ 'text': z.string().readonly(),
29
+ })]).readonly(),
30
+ })]))
31
+ let _qilin_agent_commands_commands_list_parameter_0$schema$value
32
+ const _qilin_agent_commands_commands_list_parameter_0$schema = () => (_qilin_agent_commands_commands_list_parameter_0$schema$value ??= z.intersection(z.string(), z.unknown()))
33
+ let _qilin_agent_commands_commands_list_result$schema$value
34
+ const _qilin_agent_commands_commands_list_result$schema = () => (_qilin_agent_commands_commands_list_result$schema$value ??= z.array(z.object({
35
+ 'definitionId': z.intersection(z.string(), z.unknown()).readonly().optional(),
36
+ 'name': z.string().readonly(),
37
+ 'description': z.string().readonly(),
38
+ 'input': z.object({
39
+ 'hint': z.string().readonly(),
40
+ 'attachments': z.boolean().readonly().optional(),
41
+ }).readonly().optional(),
42
+ })))
43
+
44
+ export const TYPERT_REMOTE = {
45
+ package: '@qilin-agent/commands',
46
+ descriptors: [
47
+ {
48
+ id: '@qilin-agent/commands#commands/execute',
49
+ service: 'commands',
50
+ namespace: 'commands',
51
+ method: 'execute',
52
+ invocation: { kind: 'direct' },
53
+ scope: {
54
+ context: 'agent',
55
+ wire: 'agentId',
56
+ },
57
+ parameters: [
58
+ {
59
+ name: 'agent',
60
+ wire: 'agentId',
61
+ source: 'lookup',
62
+ lookup: 'agent',
63
+ codec: {
64
+ mode: 'strict',
65
+ typeSymbol: '@qilin-agent/session/types#SessionId',
66
+ create: _qilin_agent_commands_commands_execute_parameter_0$schema,
67
+ },
68
+ },
69
+ {
70
+ name: 'line',
71
+ wire: 'line',
72
+ source: 'json',
73
+ codec: {
74
+ mode: 'strict',
75
+ typeSymbol: '@qilin-agent/commands#commands/execute:line',
76
+ create: _qilin_agent_commands_commands_execute_parameter_1$schema,
77
+ },
78
+ },
79
+ {
80
+ name: 'submittedAttachments',
81
+ wire: 'submittedAttachments',
82
+ source: 'json',
83
+ codec: {
84
+ mode: 'strict',
85
+ typeSymbol: '@qilin-agent/commands#commands/execute:submittedAttachments',
86
+ create: _qilin_agent_commands_commands_execute_parameter_2$schema,
87
+ },
88
+ },
89
+ ],
90
+ cancellation: { parameter: 'signal' },
91
+ result: {
92
+ mode: 'strict',
93
+ typeSymbol: '@qilin-agent/commands#commands/execute:result',
94
+ create: _qilin_agent_commands_commands_execute_result$schema,
95
+ },
96
+ sourceLocation: {"file":"packages/interaction/commands/src/index.ts","line":361,"column":9},
97
+ },
98
+ {
99
+ id: '@qilin-agent/commands#commands/list',
100
+ service: 'commands',
101
+ namespace: 'commands',
102
+ method: 'list',
103
+ invocation: { kind: 'direct' },
104
+ scope: {
105
+ context: 'agent',
106
+ wire: 'agentId',
107
+ },
108
+ parameters: [
109
+ {
110
+ name: 'agent',
111
+ wire: 'agentId',
112
+ source: 'lookup',
113
+ lookup: 'agent',
114
+ codec: {
115
+ mode: 'strict',
116
+ typeSymbol: '@qilin-agent/session/types#SessionId',
117
+ create: _qilin_agent_commands_commands_list_parameter_0$schema,
118
+ },
119
+ },
120
+ ],
121
+ result: {
122
+ mode: 'strict',
123
+ typeSymbol: '@qilin-agent/commands#commands/list:result',
124
+ create: _qilin_agent_commands_commands_list_result$schema,
125
+ },
126
+ sourceLocation: {"file":"packages/interaction/commands/src/index.ts","line":315,"column":3},
127
+ },
128
+ ],
129
+ }
130
+
131
+ export default TYPERT_REMOTE
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Command definition identities and execution ids for discovery and lifecycle pairing.
3
+ *
4
+ * The `Branded<B>` primitive lives in `@qilin-agent/brand`; this module
5
+ * is a pure type/constructor outlet (no cordis imports, no module
6
+ * augmentation) so wire and client programs can name the brand without
7
+ * loading the host plugin's Context merges — the `qilin-llm/brand` shape.
8
+ *
9
+ * @module @qilin-agent/commands/brand
10
+ */
11
+ import type { Branded } from '@qilin-agent/brand';
12
+ /** Stable, plugin-owned identity of a command definition, independent of its name and copy. */
13
+ export type CommandDefinitionId = Branded<'CommandDefinitionId'>;
14
+ /**
15
+ * Brand a plugin-namespaced command definition identity.
16
+ * @param id - stable identity chosen by the registering plugin.
17
+ * @returns the same string, branded; no validation is performed.
18
+ */
19
+ export declare function CommandDefinitionId(id: string): CommandDefinitionId;
20
+ /**
21
+ * Pairs one command execution's `command/run`/`command/done` lifecycle
22
+ * records with each other and with the `command.execute` admission response.
23
+ * Minted by the executor, monotonic per service instance.
24
+ */
25
+ export type CommandId = Branded<'CommandId'>;
26
+ /**
27
+ * Brand a string as a {@link CommandId}.
28
+ * @param id - the executor-minted pairing id.
29
+ * @returns the same string, branded; no validation is performed.
30
+ */
31
+ export declare function CommandId(id: string): CommandId;
32
+ //# sourceMappingURL=brand.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Command definition identities and execution ids for discovery and lifecycle pairing.
3
+ *
4
+ * The `Branded<B>` primitive lives in `@qilin-agent/brand`; this module
5
+ * is a pure type/constructor outlet (no cordis imports, no module
6
+ * augmentation) so wire and client programs can name the brand without
7
+ * loading the host plugin's Context merges — the `qilin-llm/brand` shape.
8
+ *
9
+ * @module @qilin-agent/commands/brand
10
+ */
11
+ /**
12
+ * Brand a plugin-namespaced command definition identity.
13
+ * @param id - stable identity chosen by the registering plugin.
14
+ * @returns the same string, branded; no validation is performed.
15
+ */
16
+ export function CommandDefinitionId(id) {
17
+ return id;
18
+ }
19
+ /**
20
+ * Brand a string as a {@link CommandId}.
21
+ * @param id - the executor-minted pairing id.
22
+ * @returns the same string, branded; no validation is performed.
23
+ */
24
+ export function CommandId(id) {
25
+ return id;
26
+ }
27
+ //# sourceMappingURL=brand.js.map
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Plugin-owned human-command registry shared by interactive UI adapters.
3
+ * @module @qilin-agent/commands
4
+ */
5
+ import { Context } from '@qilin-agent/kylin';
6
+ import type { Agent } from '@qilin-agent/agent';
7
+ import type { FileAttachmentRef } from '@qilin-agent/attachment/types';
8
+ import type { FileBlock, ImageBlock } from '@qilin-agent/llm';
9
+ import { TypertRemoteService } from '@qilin-agent/typert-protocol';
10
+ import { CommandId } from './brand.ts';
11
+ import type { CommandDefinitionId } from './brand.ts';
12
+ import type { CommandDescriptor, CommandExecution, CommandInputDescriptor, CommandResult, CommandSubmitAttachment } from './types.ts';
13
+ export { CommandDefinitionId, CommandId } from './brand.ts';
14
+ export type * from './types.ts';
15
+ export declare const name = "commands";
16
+ /** Host resolver for Session-scoped staged file-upload receipts. */
17
+ export type CommandFileReceiptResolver = (agent: Agent, receiptId: string) => FileAttachmentRef | undefined;
18
+ /** Invocation passed to one registered command handler. */
19
+ export interface CommandInvocation {
20
+ /** Pairing id already written to this invocation's `command/run` event. */
21
+ readonly commandId: CommandId;
22
+ /** Exact agent whose UI received the command. */
23
+ readonly agent: Agent;
24
+ /** Exact text following the registered command name, including separator whitespace. */
25
+ readonly rawInput: string;
26
+ /**
27
+ * Durably admitted image and file blocks accompanying this invocation, in submission
28
+ * order; empty unless the definition declares `input.attachments`. The handler
29
+ * owns their model-visible use — the registry never schedules them itself —
30
+ * and a handler whose grammar cannot use them in this invocation returns an
31
+ * error so the dispatching composer retains the originals.
32
+ */
33
+ readonly attachments: readonly (ImageBlock | FileBlock)[];
34
+ /** Cancellation signal owned by the dispatching UI request. */
35
+ readonly signal: AbortSignal;
36
+ }
37
+ /** Plugin-owned command registration. */
38
+ export interface CommandDefinition {
39
+ /** Stable plugin-owned identity; absent for definitions without identity-based client behavior. */
40
+ readonly definitionId?: CommandDefinitionId;
41
+ /** Lowercase command name without the leading slash. */
42
+ readonly name: string;
43
+ /** Human-readable summary used in discovery UI. */
44
+ readonly description: string;
45
+ /** Optional free-form input hint advertised to capable clients. */
46
+ readonly input?: CommandInputDescriptor;
47
+ /**
48
+ * Whether `command/run` records `rawInput`. Defaults to true. A command
49
+ * whose domain event owns the payload sets this false to avoid duplicating
50
+ * that payload in the session log.
51
+ */
52
+ readonly recordInput?: boolean;
53
+ /** Execute against the receiving agent without sending the command to the model. */
54
+ readonly handler: (invocation: CommandInvocation) => CommandResult | Promise<CommandResult>;
55
+ }
56
+ /** Syntactically valid slash command before registry resolution. */
57
+ export interface ParsedCommand {
58
+ /** Lowercase command name without the leading slash. */
59
+ readonly name: string;
60
+ /** Exact text following the command name. */
61
+ readonly rawInput: string;
62
+ }
63
+ declare module '@qilin-agent/kylin' {
64
+ interface Context {
65
+ commands: CommandRuntime;
66
+ }
67
+ }
68
+ /**
69
+ * Parse an exact slash command without normalizing its trailing input.
70
+ *
71
+ * @param line - Complete candidate command line.
72
+ * @returns The parsed command, or `undefined` when the line is not a command.
73
+ */
74
+ export declare function parseCommand(line: string): ParsedCommand | undefined;
75
+ /**
76
+ * Human-command registry. Plain-context definitions are global; definitions
77
+ * registered through a command-injected child of an agent context shadow
78
+ * globals for that agent.
79
+ */
80
+ export declare class CommandRuntime extends TypertRemoteService {
81
+ private readonly layers;
82
+ /** Monotonic per-instance counter behind {@link mintCommandId}. */
83
+ private commandSeq;
84
+ /** Instance token keeping minted ids unique across process restarts over one resumed log. */
85
+ private readonly instanceToken;
86
+ /** Optional provider installed by the Session upload owner. */
87
+ private readonly fileReceipts;
88
+ constructor(ctx: Context);
89
+ /**
90
+ * Register a global or calling-agent-scoped command.
91
+ * @param definition - discovery metadata and direct UI handler.
92
+ * @returns the exact effect disposer that unregisters this definition.
93
+ */
94
+ register(definition: CommandDefinition): () => void;
95
+ /**
96
+ * Register the sole authority that resolves staged file receipts for command submissions.
97
+ * @param resolver - Session-aware receipt resolver.
98
+ * @returns disposer that removes this exact resolver.
99
+ */
100
+ registerFileReceiptResolver(resolver: CommandFileReceiptResolver): () => void;
101
+ /**
102
+ * List the effective immutable command descriptors for one agent.
103
+ * @param agent - exact receiving agent and scoped-layer key.
104
+ * @returns name-sorted descriptors after scoped shadowing.
105
+ */
106
+ list(agent: Agent): readonly CommandDescriptor[];
107
+ /**
108
+ * Resolve one effective command definition.
109
+ * @param agent - exact receiving agent and scoped-layer key.
110
+ * @param name - command name without a slash.
111
+ * @returns the scoped shadow or global definition.
112
+ */
113
+ find(agent: Agent, name: string): CommandDefinition | undefined;
114
+ /**
115
+ * Parse and execute a known command without sending it to the model.
116
+ *
117
+ * A resolved command's lifecycle is logged: `command/run` is appended
118
+ * before the handler is invoked and `command/done` after settlement (a
119
+ * thrown or aborted handler settles as `kind: 'error'`). Both are direct
120
+ * log-only appends — no turn wraps them, and persistence drains them at
121
+ * ordinary checkpoints. Admission misses (syntax or unknown name) log
122
+ * nothing — they never entered a handler. A `command/run` append failure
123
+ * fails the execution loud; a `command/done` append failure on the
124
+ * handler-failure path is contained so the handler's own error stays the
125
+ * reported failure.
126
+ *
127
+ * Attachment admission is enforced here, not in the composer: attachments sent to a
128
+ * command that does not declare `input.attachments`, an absent attachment store,
129
+ * and an exceeded image limit each settle as an error result before
130
+ * the handler runs. Validation rejection starts no attachment writes;
131
+ * a storage failure can leave only unreachable content-addressed objects
132
+ * for deferred collection.
133
+ *
134
+ * @param agent - exact receiving agent.
135
+ * @param line - complete slash-command line.
136
+ * @param submittedAttachments - encoded images and staged file receipts accompanying the line,
137
+ * in submission order; empty for a plain invocation.
138
+ * @param signal - cancellation signal owned by the UI request.
139
+ * @returns the settled execution (result + lifecycle pairing id), or
140
+ * `undefined` when syntax or name does not resolve.
141
+ */
142
+ execute(agent: Agent, line: string, submittedAttachments: readonly CommandSubmitAttachment[], signal: AbortSignal): Promise<CommandExecution | undefined>;
143
+ /** Contained `command/done` error append for a thrown handler or admission failure. */
144
+ private settleThrown;
145
+ /** Mint the next pairing id (monotonic; instance-token-prefixed so a resumed log never repeats one). */
146
+ private mintCommandId;
147
+ /**
148
+ * Append one log-only lifecycle event directly: no turn is opened for it and
149
+ * no flush is forced — persistence observes the eager `session/event` path
150
+ * and drains at ordinary checkpoints and teardown, like every other
151
+ * standalone plugin event.
152
+ */
153
+ private appendLifecycle;
154
+ /** Resolve global definitions followed by exact scoped shadows. */
155
+ private view;
156
+ /** Notify every registry observer without making UI refresh load-bearing. */
157
+ private notifyChange;
158
+ }
159
+ export default CommandRuntime;
160
+ //# sourceMappingURL=index.d.ts.map