@volter/twin-togetherai 0.1.0
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/LICENSE +202 -0
- package/README.md +147 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +28 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +79 -0
- package/dist/src/togetherai-budget.d.ts +52 -0
- package/dist/src/togetherai-budget.js +130 -0
- package/dist/src/togetherai-capabilities.d.ts +4 -0
- package/dist/src/togetherai-capabilities.js +1428 -0
- package/dist/src/togetherai-conformance.d.ts +14 -0
- package/dist/src/togetherai-conformance.js +452 -0
- package/dist/src/togetherai-connector.d.ts +164 -0
- package/dist/src/togetherai-connector.js +457 -0
- package/dist/src/togetherai-models.d.ts +19 -0
- package/dist/src/togetherai-models.js +49 -0
- package/dist/src/togetherai-scenario.d.ts +52 -0
- package/dist/src/togetherai-scenario.js +168 -0
- package/dist/src/togetherai-server.d.ts +16 -0
- package/dist/src/togetherai-server.js +187 -0
- package/dist/src/togetherai-stub.d.ts +59 -0
- package/dist/src/togetherai-stub.js +195 -0
- package/dist/src/togetherai-twin.d.ts +83 -0
- package/dist/src/togetherai-twin.js +1419 -0
- package/dist/src/togetherai-types.d.ts +207 -0
- package/dist/src/togetherai-types.js +26 -0
- package/package.json +52 -0
- package/src/cli.ts +27 -0
- package/src/index.ts +118 -0
- package/src/togetherai-budget.ts +156 -0
- package/src/togetherai-capabilities.ts +1315 -0
- package/src/togetherai-conformance.ts +459 -0
- package/src/togetherai-connector.ts +496 -0
- package/src/togetherai-models.ts +74 -0
- package/src/togetherai-scenario.ts +185 -0
- package/src/togetherai-server.ts +199 -0
- package/src/togetherai-stub.ts +197 -0
- package/src/togetherai-twin.ts +1448 -0
- package/src/togetherai-types.ts +222 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Shared wire-shape types for the Together AI surface. These mirror the REAL vendor JSON shapes
|
|
2
|
+
// as published by Together's own OpenAPI (https://docs.together.ai/openapi.yaml, fetched
|
|
3
|
+
// 2026-09-16) and the Stainless-generated `together-ai@0.53.0` SDK — NOT the SDK's internal
|
|
4
|
+
// types (the twin never imports the SDK at runtime; the SDK is exercised only in *.test.ts).
|
|
5
|
+
//
|
|
6
|
+
// TOGETHER IS NOT OPENAI, and the differences below are load-bearing (they are what a
|
|
7
|
+
// "just copy the openai pack" twin gets wrong):
|
|
8
|
+
// • `n` spans 1–128 (OpenAI-compatible; Groq pins it at 1) and `logprobs` is an INTEGER 0–20
|
|
9
|
+
// (OpenAI's boolean) — Together serves both;
|
|
10
|
+
// • `finish_reason` adds **`eos`** (Together's end-of-sequence token) alongside stop/length;
|
|
11
|
+
// • the response carries a REQUIRED `prompt: []` array (the echoed prompt when `echo:true`);
|
|
12
|
+
// • the error envelope is `{ error: { message, type, param, code } }` with `param`/`code`
|
|
13
|
+
// nullable, and Together's STATUS TABLE is its own: 402 = monthly spending limit,
|
|
14
|
+
// **403 = context length exceeded** (a BAD REQUEST, not a permission denial),
|
|
15
|
+
// 503 = engine overloaded, 524 = Cloudflare timeout, 529 = server error;
|
|
16
|
+
// • the batch surface is Together-NATIVE: `GET /v1/batches` answers a bare ARRAY (not an
|
|
17
|
+
// OpenAI `{object:'list',data}` envelope), `POST /v1/batches` answers 201 with
|
|
18
|
+
// `BatchJobWithWarning { job, warning? }`, and every batch error is `{ error: string }`
|
|
19
|
+
// (a bare string, NOT an ErrorData object);
|
|
20
|
+
// • files carry Together's own `FileType` (csv|jsonl|parquet) and the validation pipeline's
|
|
21
|
+
// `processing_status` / `validation_report`;
|
|
22
|
+
// • model ids are slash-namespaced (`meta-llama/Llama-3.3-70B-Instruct-Turbo`) and an
|
|
23
|
+
// OpenAI-style flat id like `gpt-4o` is a 404;
|
|
24
|
+
// • `service_tier` / `store` / `metadata` / `prediction` are ACCEPTED BUT IGNORED (the
|
|
25
|
+
// OpenAI-compat page's own wording) — accepted here, never echoed into the response.
|
|
26
|
+
|
|
27
|
+
// ── Chat Completions ────────────────────────────────────────────────────────────────────
|
|
28
|
+
/** A chat message param as the caller sends it. Together's `ChatCompletionMessageParam` oneOf
|
|
29
|
+
* covers system/user/assistant/tool/function; content is a string (Together's schema types
|
|
30
|
+
* every param's content as `string | null` — no content-part arrays). */
|
|
31
|
+
export type TogetheraiMessageParam = {
|
|
32
|
+
role: 'system' | 'user' | 'assistant' | 'tool' | 'function';
|
|
33
|
+
content?: string | null;
|
|
34
|
+
name?: string;
|
|
35
|
+
tool_calls?: TogetheraiToolCall[];
|
|
36
|
+
tool_call_id?: string;
|
|
37
|
+
// Assistant-turn fields Together's own schema declares:
|
|
38
|
+
reasoning?: string | null;
|
|
39
|
+
reasoning_content?: string | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** A function tool_call inside an assistant message (Together's `ToolChoice`). */
|
|
43
|
+
export type TogetheraiToolCall = {
|
|
44
|
+
id: string;
|
|
45
|
+
type: 'function';
|
|
46
|
+
function: { name: string; arguments: string };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Together's `UsageData`: the three token counts, REQUIRED and NULLABLE (Together reports
|
|
50
|
+
* `null` usage on some streamed/failed turns). No timing fields — that is Groq's block. */
|
|
51
|
+
export type TogetheraiUsage = {
|
|
52
|
+
prompt_tokens: number | null;
|
|
53
|
+
completion_tokens: number | null;
|
|
54
|
+
total_tokens: number | null;
|
|
55
|
+
/** Reasoning models nest the detail blocks (Together's docs: cached/reasoning token splits). */
|
|
56
|
+
prompt_tokens_details?: { cached_tokens: number } | null;
|
|
57
|
+
completion_tokens_details?: { reasoning_tokens: number } | null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Together's assistant message. `reasoning`/`reasoning_content` vary by model (Together's docs:
|
|
61
|
+
* "varies by model" — both are declared on the schema). No `refusal` field. */
|
|
62
|
+
export type TogetheraiAssistantMessage = {
|
|
63
|
+
role: 'assistant';
|
|
64
|
+
content: string | null;
|
|
65
|
+
tool_calls?: TogetheraiToolCall[];
|
|
66
|
+
function_call?: { name: string; arguments: string };
|
|
67
|
+
reasoning?: string | null;
|
|
68
|
+
reasoning_content?: string | null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** Together's `FinishReason`: adds **`eos`** to the OpenAI set. */
|
|
72
|
+
export type TogetheraiFinishReason = 'stop' | 'eos' | 'length' | 'tool_calls' | 'function_call';
|
|
73
|
+
|
|
74
|
+
export type TogetheraiChoice = {
|
|
75
|
+
index: number;
|
|
76
|
+
message?: TogetheraiAssistantMessage;
|
|
77
|
+
text?: string;
|
|
78
|
+
seed?: number;
|
|
79
|
+
logprobs?: unknown | null;
|
|
80
|
+
finish_reason: TogetheraiFinishReason | null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** The unary chat.completion response. `prompt` is REQUIRED on Together's schema — the echoed
|
|
84
|
+
* prompt parts (empty unless `echo:true`); `warnings` is Together's inference-warnings array. */
|
|
85
|
+
export type TogetheraiChatCompletion = {
|
|
86
|
+
id: string;
|
|
87
|
+
object: 'chat.completion';
|
|
88
|
+
created: number;
|
|
89
|
+
model: string;
|
|
90
|
+
choices: TogetheraiChoice[];
|
|
91
|
+
prompt: Array<{ text?: string; logprobs?: unknown }>;
|
|
92
|
+
usage?: TogetheraiUsage | null;
|
|
93
|
+
warnings?: unknown[];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// ── Streaming ───────────────────────────────────────────────────────────────────────────
|
|
97
|
+
/** A single Server-Sent Event the streaming path emits (collected, never socketed in tests).
|
|
98
|
+
* `data` is the JSON payload; `[DONE]` is signalled with `done: true` (no data object). */
|
|
99
|
+
export type SseEvent = { data?: Record<string, unknown>; done?: boolean };
|
|
100
|
+
|
|
101
|
+
/** A sink the streaming path writes events into (an injected collector in tests / a real
|
|
102
|
+
* HTTP SSE writer in the server). NO real sockets or setTimeout in the handler. */
|
|
103
|
+
export type SseSink = (event: SseEvent) => void;
|
|
104
|
+
|
|
105
|
+
/** A streaming chunk. Together's `ChatCompletionChunk` carries `usage` (nullable) and
|
|
106
|
+
* `warnings` on EVERY chunk (OpenAI puts usage only in an opt-in tail chunk). */
|
|
107
|
+
export type TogetheraiChunk = {
|
|
108
|
+
id: string;
|
|
109
|
+
object: 'chat.completion.chunk';
|
|
110
|
+
created: number;
|
|
111
|
+
model: string;
|
|
112
|
+
system_fingerprint?: string;
|
|
113
|
+
choices: Array<{ index: number; delta: Record<string, unknown>; logprobs?: unknown | null; finish_reason: TogetheraiFinishReason | null }>;
|
|
114
|
+
usage?: TogetheraiUsage | null;
|
|
115
|
+
warnings?: unknown[];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// ── Models ──────────────────────────────────────────────────────────────────────────────
|
|
119
|
+
/** Together's `ModelInfo`: REQUIRED keys are id/object/created/type — `type` is Together's OWN
|
|
120
|
+
* enum (chat|language|code|image|embedding|moderation|rerank), not OpenAI's flat model object. */
|
|
121
|
+
export type TogetheraiModel = {
|
|
122
|
+
id: string;
|
|
123
|
+
object: 'model';
|
|
124
|
+
created: number;
|
|
125
|
+
type: 'chat' | 'language' | 'code' | 'image' | 'embedding' | 'moderation' | 'rerank';
|
|
126
|
+
display_name?: string;
|
|
127
|
+
organization?: string;
|
|
128
|
+
link?: string;
|
|
129
|
+
license?: string;
|
|
130
|
+
context_length?: number;
|
|
131
|
+
pricing?: Record<string, unknown>;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// ── Embeddings ──────────────────────────────────────────────────────────────────────────
|
|
135
|
+
export type TogetheraiEmbedding = { object: 'embedding'; index: number; embedding: number[] };
|
|
136
|
+
/** Together's `EmbeddingsResponse`: REQUIRED object/model/data — and NO `usage` key on the
|
|
137
|
+
* schema (Together does not document one on this endpoint). */
|
|
138
|
+
export type TogetheraiEmbeddingResponse = {
|
|
139
|
+
object: 'list';
|
|
140
|
+
model: string;
|
|
141
|
+
data: TogetheraiEmbedding[];
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// ── Rerank ──────────────────────────────────────────────────────────────────────────────
|
|
145
|
+
/** Together's `RerankResponse` — Together-native (NOT an OpenAI endpoint at all). */
|
|
146
|
+
export type TogetheraiRerankResponse = {
|
|
147
|
+
object: 'rerank';
|
|
148
|
+
id?: string;
|
|
149
|
+
model: string;
|
|
150
|
+
results: Array<{ index: number; relevance_score: number; document?: { text?: string | null } }>;
|
|
151
|
+
usage?: TogetheraiUsage | null;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// ── Images ──────────────────────────────────────────────────────────────────────────────
|
|
155
|
+
/** Together's `ImageResponse`: `object:'list'` with a discriminated data union
|
|
156
|
+
* (`type:'url'` | `type:'b64_json'`). */
|
|
157
|
+
export type TogetheraiImageResponse = {
|
|
158
|
+
id: string;
|
|
159
|
+
model: string;
|
|
160
|
+
object: 'list';
|
|
161
|
+
data: Array<{ index: number; url?: string; b64_json?: string; type: 'url' | 'b64_json' }>;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ── Files ───────────────────────────────────────────────────────────────────────────────
|
|
165
|
+
/** Together's `FilePurpose` — a CLOSED set (`fine-tune` | `eval` | `batch-api`), NOT OpenAI's. */
|
|
166
|
+
export type TogetheraiFilePurpose = 'fine-tune' | 'eval' | 'batch-api';
|
|
167
|
+
/** Together's `FileType` — csv|jsonl|parquet. */
|
|
168
|
+
export type TogetheraiFileType = 'csv' | 'jsonl' | 'parquet';
|
|
169
|
+
/** The validation pipeline's lifecycle state (fine-tune files only). */
|
|
170
|
+
export type TogetheraiFileProcessingStatus = 'PENDING' | 'QUEUED' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'INVALID_FORMAT';
|
|
171
|
+
|
|
172
|
+
/** Together's `FileResponse`. REQUIRED keys include Together's own `FileType` (capital F) and
|
|
173
|
+
* the deprecated `Processed` boolean. */
|
|
174
|
+
export type TogetheraiFile = {
|
|
175
|
+
id: string;
|
|
176
|
+
object: 'file';
|
|
177
|
+
created_at: number;
|
|
178
|
+
filename: string;
|
|
179
|
+
bytes: number;
|
|
180
|
+
purpose: TogetheraiFilePurpose;
|
|
181
|
+
Processed: boolean;
|
|
182
|
+
FileType: TogetheraiFileType;
|
|
183
|
+
processing_status?: TogetheraiFileProcessingStatus;
|
|
184
|
+
validation_report?: { valid: boolean; [k: string]: unknown };
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// ── Batches (Together-native) ───────────────────────────────────────────────────────────
|
|
188
|
+
/** Together's `BatchJobStatus` — UPPER-CASE, not OpenAI's lowercase set. */
|
|
189
|
+
export type TogetheraiBatchStatus = 'VALIDATING' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED' | 'EXPIRED' | 'CANCELLED';
|
|
190
|
+
/** Together's `CreateBatchRequest.endpoint` — the three documented endpoints. */
|
|
191
|
+
export type TogetheraiBatchEndpoint = '/v1/chat/completions' | '/v1/audio/transcriptions' | '/v1/audio/translations';
|
|
192
|
+
|
|
193
|
+
/** Together's `BatchJob`. `error` is a bare STRING (not an ErrorData object), and the
|
|
194
|
+
* timestamps are ISO date-time STRINGS (not OpenAI's unix integers). */
|
|
195
|
+
export type TogetheraiBatch = {
|
|
196
|
+
id: string;
|
|
197
|
+
user_id?: string;
|
|
198
|
+
input_file_id: string;
|
|
199
|
+
file_size_bytes?: number;
|
|
200
|
+
status: TogetheraiBatchStatus;
|
|
201
|
+
job_deadline?: string | null;
|
|
202
|
+
created_at: string;
|
|
203
|
+
endpoint: string;
|
|
204
|
+
progress?: number;
|
|
205
|
+
model_id?: string;
|
|
206
|
+
output_file_id?: string | null;
|
|
207
|
+
error_file_id?: string | null;
|
|
208
|
+
error?: string | null;
|
|
209
|
+
completed_at?: string | null;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// ── Errors ──────────────────────────────────────────────────────────────────────────────
|
|
213
|
+
/** Together's `ErrorData`: `{ error: { message, type, param, code } }` with `message`+`type`
|
|
214
|
+
* REQUIRED and `param`/`code` nullable with default null. */
|
|
215
|
+
export type TogetheraiError = {
|
|
216
|
+
error: {
|
|
217
|
+
message: string;
|
|
218
|
+
type: string;
|
|
219
|
+
param?: string | null;
|
|
220
|
+
code?: string | null;
|
|
221
|
+
};
|
|
222
|
+
};
|