@harny/sdk 0.1.2 → 0.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.
Files changed (81) hide show
  1. package/dist/cjs/agent/adapters.d.ts +167 -0
  2. package/dist/cjs/agent/adapters.js +557 -0
  3. package/dist/cjs/agent/adapters.js.map +1 -0
  4. package/dist/cjs/agent/hooks.d.ts +52 -0
  5. package/dist/cjs/agent/hooks.js +41 -0
  6. package/dist/cjs/agent/hooks.js.map +1 -0
  7. package/dist/cjs/agent/index.d.ts +34 -0
  8. package/dist/cjs/agent/index.js +62 -0
  9. package/dist/cjs/agent/index.js.map +1 -0
  10. package/dist/cjs/agent/loop.d.ts +401 -0
  11. package/dist/cjs/agent/loop.js +1252 -0
  12. package/dist/cjs/agent/loop.js.map +1 -0
  13. package/dist/cjs/agent/roster.d.ts +62 -0
  14. package/dist/cjs/agent/roster.js +149 -0
  15. package/dist/cjs/agent/roster.js.map +1 -0
  16. package/dist/cjs/agent/session.d.ts +106 -0
  17. package/dist/cjs/agent/session.js +261 -0
  18. package/dist/cjs/agent/session.js.map +1 -0
  19. package/dist/cjs/agent/spend.d.ts +39 -0
  20. package/dist/cjs/agent/spend.js +70 -0
  21. package/dist/cjs/agent/spend.js.map +1 -0
  22. package/dist/cjs/agent/tools.d.ts +83 -0
  23. package/dist/cjs/agent/tools.js +212 -0
  24. package/dist/cjs/agent/tools.js.map +1 -0
  25. package/dist/cjs/agent/tracing.d.ts +72 -0
  26. package/dist/cjs/agent/tracing.js +128 -0
  27. package/dist/cjs/agent/tracing.js.map +1 -0
  28. package/dist/cjs/agent/util.d.ts +60 -0
  29. package/dist/cjs/agent/util.js +188 -0
  30. package/dist/cjs/agent/util.js.map +1 -0
  31. package/dist/cjs/conflictQuestion.d.ts +137 -0
  32. package/dist/cjs/conflictQuestion.js +356 -0
  33. package/dist/cjs/conflictQuestion.js.map +1 -0
  34. package/dist/cjs/index.d.ts +950 -0
  35. package/dist/cjs/index.js +1124 -0
  36. package/dist/cjs/index.js.map +1 -0
  37. package/dist/cjs/memoryV1.d.ts +121 -0
  38. package/dist/cjs/memoryV1.js +132 -0
  39. package/dist/cjs/memoryV1.js.map +1 -0
  40. package/dist/cjs/package.json +1 -0
  41. package/dist/esm/agent/adapters.d.ts +167 -0
  42. package/dist/esm/agent/adapters.js +543 -0
  43. package/dist/esm/agent/adapters.js.map +1 -0
  44. package/dist/esm/agent/hooks.d.ts +52 -0
  45. package/dist/esm/agent/hooks.js +36 -0
  46. package/dist/esm/agent/hooks.js.map +1 -0
  47. package/dist/esm/agent/index.d.ts +34 -0
  48. package/dist/esm/agent/index.js +28 -0
  49. package/dist/esm/agent/index.js.map +1 -0
  50. package/dist/esm/agent/loop.d.ts +401 -0
  51. package/dist/esm/agent/loop.js +1243 -0
  52. package/dist/esm/agent/loop.js.map +1 -0
  53. package/dist/esm/agent/roster.d.ts +62 -0
  54. package/dist/esm/agent/roster.js +143 -0
  55. package/dist/esm/agent/roster.js.map +1 -0
  56. package/dist/esm/agent/session.d.ts +106 -0
  57. package/dist/esm/agent/session.js +221 -0
  58. package/dist/esm/agent/session.js.map +1 -0
  59. package/dist/esm/agent/spend.d.ts +39 -0
  60. package/dist/esm/agent/spend.js +65 -0
  61. package/dist/esm/agent/spend.js.map +1 -0
  62. package/dist/esm/agent/tools.d.ts +83 -0
  63. package/dist/esm/agent/tools.js +205 -0
  64. package/dist/esm/agent/tools.js.map +1 -0
  65. package/dist/esm/agent/tracing.d.ts +72 -0
  66. package/dist/esm/agent/tracing.js +119 -0
  67. package/dist/esm/agent/tracing.js.map +1 -0
  68. package/dist/esm/agent/util.d.ts +60 -0
  69. package/dist/esm/agent/util.js +168 -0
  70. package/dist/esm/agent/util.js.map +1 -0
  71. package/dist/esm/conflictQuestion.d.ts +137 -0
  72. package/dist/esm/conflictQuestion.js +346 -0
  73. package/dist/esm/conflictQuestion.js.map +1 -0
  74. package/dist/esm/index.d.ts +950 -0
  75. package/dist/esm/index.js +1072 -0
  76. package/dist/esm/index.js.map +1 -0
  77. package/dist/esm/memoryV1.d.ts +121 -0
  78. package/dist/esm/memoryV1.js +124 -0
  79. package/dist/esm/memoryV1.js.map +1 -0
  80. package/dist/esm/package.json +1 -0
  81. package/package.json +2 -3
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Model adapters: three wire styles, configured entirely from a roster entry.
3
+ *
4
+ * The loop speaks one neutral shape (messages, tool specs, tool calls). An
5
+ * adapter translates it to one wire style and back:
6
+ *
7
+ * - `chat_completions`: the widely shared chat-completions request shape.
8
+ * - `messages`: the messages request shape with content blocks.
9
+ * - `generate_content`: the generate-content shape with function declarations.
10
+ *
11
+ * Which provider speaks which style, the base URL, the auth header, any fixed
12
+ * headers and any extra request-body fields (a pin to one host on a provider
13
+ * that routes to many) all come from the roster entry, so no provider or model
14
+ * name is written here and a new provider on an existing style is a roster edit.
15
+ *
16
+ * Within one run, the model's own assistant turns are replayed in the native
17
+ * form the provider returned (some providers require their reasoning or
18
+ * signature fields back on the next call), with one repair: a tool call whose
19
+ * arguments are not a JSON object is replayed with `{}` (the loop has already
20
+ * answered it as invalid), because some hosts refuse the whole request
21
+ * otherwise. Across runs the session store keeps plain text and action notes
22
+ * only, so a conversation survives a change of preset or provider.
23
+ *
24
+ * A model that thinks before it answers (`thinking_always_on` in its roster
25
+ * entry; the agent never switches thinking off) spends part of the answer
26
+ * limit thinking. Its adapter gives every call at least the entry's
27
+ * `answer_room_tokens`; only the tokens the model uses are billed, and the
28
+ * thinking itself is never capped. A turn the provider stopped at the limit,
29
+ * or before it finished for another documented reason, is marked `cutOff`.
30
+ */
31
+ import type { ResolvedModel } from "./roster.js";
32
+ export interface ToolSpec {
33
+ readonly name: string;
34
+ readonly description: string;
35
+ readonly parameters: Record<string, unknown>;
36
+ }
37
+ export interface ToolCall {
38
+ readonly id: string;
39
+ readonly name: string;
40
+ /** `null` when the model's arguments were not a JSON object (see `parseError`). */
41
+ readonly arguments: Record<string, unknown> | null;
42
+ readonly parseError?: string | null;
43
+ }
44
+ export interface ToolResult {
45
+ readonly callId: string;
46
+ readonly name: string;
47
+ readonly content: string;
48
+ readonly isError?: boolean;
49
+ }
50
+ export declare class Usage {
51
+ inputTokens: number;
52
+ outputTokens: number;
53
+ constructor(inputTokens?: number, outputTokens?: number);
54
+ get totalTokens(): number;
55
+ add(other: Usage): void;
56
+ }
57
+ export type MessageRole = "user" | "assistant" | "tool_results";
58
+ /**
59
+ * One neutral message. `native` holds a provider's own assistant turn.
60
+ *
61
+ * A `tool_results` message may carry `text`: the loop's own words to the model
62
+ * after the results (the closing turn at the step limit), sent in the same
63
+ * turn as the results so user and model turns keep alternating.
64
+ */
65
+ export declare class Message {
66
+ readonly role: MessageRole;
67
+ readonly text: string;
68
+ readonly toolCalls: ToolCall[];
69
+ readonly results: ToolResult[];
70
+ readonly native: unknown;
71
+ readonly nativeStyle: string | null;
72
+ constructor(init: {
73
+ role: MessageRole;
74
+ text?: string;
75
+ toolCalls?: ToolCall[];
76
+ results?: ToolResult[];
77
+ native?: unknown;
78
+ nativeStyle?: string | null;
79
+ });
80
+ }
81
+ export declare class ModelTurn {
82
+ readonly text: string;
83
+ readonly toolCalls: ToolCall[];
84
+ readonly usage: Usage;
85
+ readonly stop: string;
86
+ readonly native: unknown;
87
+ constructor(text: string, toolCalls: ToolCall[], usage: Usage, stop: string, native?: unknown);
88
+ /** The provider stopped this turn before it finished: text and tool calls may be incomplete. */
89
+ get cutOff(): boolean;
90
+ /** Stopped at the answer limit (the common case of `cutOff`). */
91
+ get atAnswerLimit(): boolean;
92
+ }
93
+ /** The model provider refused or failed the call (after retries). */
94
+ export declare class ModelProviderError extends Error {
95
+ readonly statusCode: number | null;
96
+ constructor(message: string, statusCode?: number | null);
97
+ }
98
+ export interface CompleteRequest {
99
+ system: string;
100
+ messages: Message[];
101
+ tools: ToolSpec[];
102
+ maxOutputTokens: number;
103
+ /** Aborts the call (the run's time ran out). */
104
+ signal?: AbortSignal | null;
105
+ }
106
+ export interface ModelAdapter {
107
+ readonly provider: string;
108
+ readonly model: string;
109
+ readonly style: string;
110
+ complete(request: CompleteRequest): Promise<ModelTurn>;
111
+ }
112
+ export interface AdapterOptions {
113
+ /** A `fetch` to use instead of the global one (tests, proxies). */
114
+ fetch?: typeof fetch;
115
+ /** Per-call timeout. Default 60 seconds. */
116
+ timeoutMs?: number;
117
+ }
118
+ declare abstract class HttpAdapter implements ModelAdapter {
119
+ abstract readonly style: string;
120
+ readonly provider: string;
121
+ readonly model: string;
122
+ /** The answer limit a model that always thinks gets at least (`null`: no floor). */
123
+ readonly answerRoomTokens: number | null;
124
+ protected readonly base: string;
125
+ private readonly auth;
126
+ private readonly fixedHeaders;
127
+ protected readonly maxTokensParam: string;
128
+ private readonly extraBody;
129
+ private readonly fetchImpl;
130
+ private readonly timeoutMs;
131
+ constructor(resolved: ResolvedModel, options?: AdapterOptions);
132
+ /** The caller's limit, raised to the roster's answer room for a model that always thinks. */
133
+ protected answerLimit(requested: number): number;
134
+ /** The roster entry's extra fields, added where the adapter set nothing. */
135
+ protected withExtra(body: Record<string, unknown>): Record<string, unknown>;
136
+ private headers;
137
+ protected post(url: string, body: Record<string, unknown>, signal?: AbortSignal | null): Promise<Record<string, unknown>>;
138
+ abstract complete(request: CompleteRequest): Promise<ModelTurn>;
139
+ }
140
+ /** `[arguments, error]`: an object, or `null` with the reason it is not one. */
141
+ export declare function parseArguments(raw: unknown): [Record<string, unknown> | null, string | null];
142
+ /**
143
+ * The model's own turn, safe to send back: a tool call whose arguments are not
144
+ * a JSON object is replayed with `{}`. Valid arguments go back byte for byte;
145
+ * the stored turn is never changed.
146
+ */
147
+ export declare function replayable(native: unknown): unknown;
148
+ export declare class ChatCompletionsAdapter extends HttpAdapter {
149
+ readonly style = "chat_completions";
150
+ private wireMessages;
151
+ complete(request: CompleteRequest): Promise<ModelTurn>;
152
+ }
153
+ export declare class MessagesAdapter extends HttpAdapter {
154
+ readonly style = "messages";
155
+ private wireMessages;
156
+ complete(request: CompleteRequest): Promise<ModelTurn>;
157
+ }
158
+ /** Reduce a JSON schema to the subset function declarations accept. */
159
+ export declare function declarationSchema(schema: unknown): unknown;
160
+ export declare class GenerateContentAdapter extends HttpAdapter {
161
+ readonly style = "generate_content";
162
+ private wireContents;
163
+ complete(request: CompleteRequest): Promise<ModelTurn>;
164
+ }
165
+ /** The adapter for a resolved roster entry's wire style. */
166
+ export declare function buildAdapter(resolved: ResolvedModel, options?: AdapterOptions): ModelAdapter;
167
+ export {};